defcmp.pas 82 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Compare definitions and parameter lists
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit defcmp;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. cclasses,
  22. globtype,globals,
  23. node,
  24. symconst,symtype,symdef;
  25. type
  26. { if acp is cp_all the var const or nothing are considered equal }
  27. tcompare_paras_type = ( cp_none, cp_value_equal_const, cp_all,cp_procvar);
  28. tcompare_paras_option = (
  29. cpo_allowdefaults,
  30. cpo_ignorehidden, // ignore hidden parameters
  31. cpo_allowconvert,
  32. cpo_comparedefaultvalue,
  33. cpo_openequalisexact,
  34. cpo_ignoreuniv,
  35. cpo_warn_incompatible_univ,
  36. cpo_ignorevarspez, // ignore parameter access type
  37. cpo_ignoreframepointer // ignore frame pointer parameter (for assignment-compatibility of global procedures to nested procvars)
  38. );
  39. tcompare_paras_options = set of tcompare_paras_option;
  40. tcompare_defs_option = (cdo_internal,cdo_explicit,cdo_check_operator,cdo_allow_variant,cdo_parameter,cdo_warn_incompatible_univ);
  41. tcompare_defs_options = set of tcompare_defs_option;
  42. tconverttype = (tc_none,
  43. tc_equal,
  44. tc_not_possible,
  45. tc_string_2_string,
  46. tc_char_2_string,
  47. tc_char_2_chararray,
  48. tc_pchar_2_string,
  49. tc_cchar_2_pchar,
  50. tc_cstring_2_pchar,
  51. tc_cstring_2_int,
  52. tc_ansistring_2_pchar,
  53. tc_string_2_chararray,
  54. tc_chararray_2_string,
  55. tc_array_2_pointer,
  56. tc_pointer_2_array,
  57. tc_int_2_int,
  58. tc_int_2_bool,
  59. tc_bool_2_bool,
  60. tc_bool_2_int,
  61. tc_real_2_real,
  62. tc_int_2_real,
  63. tc_real_2_currency,
  64. tc_proc_2_procvar,
  65. tc_nil_2_methodprocvar,
  66. tc_arrayconstructor_2_set,
  67. tc_set_to_set,
  68. tc_cord_2_pointer,
  69. tc_intf_2_string,
  70. tc_intf_2_guid,
  71. tc_class_2_intf,
  72. tc_char_2_char,
  73. tc_dynarray_2_openarray,
  74. tc_pwchar_2_string,
  75. tc_variant_2_dynarray,
  76. tc_dynarray_2_variant,
  77. tc_variant_2_enum,
  78. tc_enum_2_variant,
  79. tc_interface_2_variant,
  80. tc_variant_2_interface,
  81. tc_array_2_dynarray
  82. );
  83. function compare_defs_ext(def_from,def_to : tdef;
  84. fromtreetype : tnodetype;
  85. var doconv : tconverttype;
  86. var operatorpd : tprocdef;
  87. cdoptions:tcompare_defs_options):tequaltype;
  88. { Returns if the type def_from can be converted to def_to or if both types are equal }
  89. function compare_defs(def_from,def_to:tdef;fromtreetype:tnodetype):tequaltype;
  90. { Returns true, if def1 and def2 are semantically the same }
  91. function equal_defs(def_from,def_to:tdef):boolean;
  92. { Checks for type compatibility (subgroups of type)
  93. used for case statements... probably missing stuff
  94. to use on other types }
  95. function is_subequal(def1, def2: tdef): boolean;
  96. {# true, if two parameter lists are equal
  97. if acp is cp_all, all have to match exactly
  98. if acp is cp_value_equal_const call by value
  99. and call by const parameter are assumed as
  100. equal
  101. if acp is cp_procvar then the varspez have to match,
  102. and all parameter types must be at least te_equal
  103. if acp is cp_none, then we don't check the varspez at all
  104. allowdefaults indicates if default value parameters
  105. are allowed (in this case, the search order will first
  106. search for a routine with default parameters, before
  107. searching for the same definition with no parameters)
  108. }
  109. function compare_paras(para1,para2 : TFPObjectList; acp : tcompare_paras_type; cpoptions: tcompare_paras_options):tequaltype;
  110. { True if a function can be assigned to a procvar }
  111. { changed first argument type to pabstractprocdef so that it can also be }
  112. { used to test compatibility between two pprocvardefs (JM) }
  113. function proc_to_procvar_equal(def1:tabstractprocdef;def2:tprocvardef;checkincompatibleuniv: boolean):tequaltype;
  114. { Parentdef is the definition of a method defined in a parent class or interface }
  115. { Childdef is the definition of a method defined in a child class, interface or }
  116. { a class implementing an interface with parentdef. }
  117. { Returns true if the resultdef of childdef can be used to implement/override }
  118. { parentdef's resultdef }
  119. function compatible_childmethod_resultdef(parentretdef, childretdef: tdef): boolean;
  120. implementation
  121. uses
  122. verbose,systems,constexp,
  123. symtable,symsym,
  124. defutil,symutil;
  125. function compare_defs_ext(def_from,def_to : tdef;
  126. fromtreetype : tnodetype;
  127. var doconv : tconverttype;
  128. var operatorpd : tprocdef;
  129. cdoptions:tcompare_defs_options):tequaltype;
  130. { tordtype:
  131. uvoid,
  132. u8bit,u16bit,u32bit,u64bit,
  133. s8bit,s16bit,s32bit,s64bit,
  134. bool8bit,bool16bit,bool32bit,bool64bit,
  135. uchar,uwidechar }
  136. type
  137. tbasedef=(bvoid,bchar,bint,bbool);
  138. const
  139. basedeftbl:array[tordtype] of tbasedef =
  140. (bvoid,
  141. bint,bint,bint,bint,
  142. bint,bint,bint,bint,
  143. bbool,bbool,bbool,bbool,bbool,
  144. bchar,bchar,bint);
  145. basedefconvertsimplicit : array[tbasedef,tbasedef] of tconverttype =
  146. { void, char, int, bool }
  147. ((tc_not_possible,tc_not_possible,tc_not_possible,tc_not_possible),
  148. (tc_not_possible,tc_char_2_char,tc_not_possible,tc_not_possible),
  149. (tc_not_possible,tc_not_possible,tc_int_2_int,tc_not_possible),
  150. (tc_not_possible,tc_not_possible,tc_not_possible,tc_bool_2_bool));
  151. basedefconvertsexplicit : array[tbasedef,tbasedef] of tconverttype =
  152. { void, char, int, bool }
  153. ((tc_not_possible,tc_not_possible,tc_not_possible,tc_not_possible),
  154. (tc_not_possible,tc_char_2_char,tc_int_2_int,tc_int_2_bool),
  155. (tc_not_possible,tc_int_2_int,tc_int_2_int,tc_int_2_bool),
  156. (tc_not_possible,tc_bool_2_int,tc_bool_2_int,tc_bool_2_bool));
  157. var
  158. subeq,eq : tequaltype;
  159. hd1,hd2 : tdef;
  160. hct : tconverttype;
  161. hobjdef : tobjectdef;
  162. hpd : tprocdef;
  163. begin
  164. eq:=te_incompatible;
  165. doconv:=tc_not_possible;
  166. { safety check }
  167. if not(assigned(def_from) and assigned(def_to)) then
  168. begin
  169. compare_defs_ext:=te_incompatible;
  170. exit;
  171. end;
  172. { same def? then we've an exact match }
  173. if def_from=def_to then
  174. begin
  175. doconv:=tc_equal;
  176. compare_defs_ext:=te_exact;
  177. exit;
  178. end;
  179. { undefined def? then mark it as equal }
  180. if (def_from.typ=undefineddef) or
  181. (def_to.typ=undefineddef) then
  182. begin
  183. doconv:=tc_equal;
  184. compare_defs_ext:=te_exact;
  185. exit;
  186. end;
  187. { we walk the wanted (def_to) types and check then the def_from
  188. types if there is a conversion possible }
  189. case def_to.typ of
  190. orddef :
  191. begin
  192. case def_from.typ of
  193. orddef :
  194. begin
  195. if (torddef(def_from).ordtype=torddef(def_to).ordtype) then
  196. begin
  197. case torddef(def_from).ordtype of
  198. uchar,uwidechar,
  199. u8bit,u16bit,u32bit,u64bit,
  200. s8bit,s16bit,s32bit,s64bit:
  201. begin
  202. if (torddef(def_from).low>=torddef(def_to).low) and
  203. (torddef(def_from).high<=torddef(def_to).high) then
  204. eq:=te_equal
  205. else
  206. begin
  207. doconv:=tc_int_2_int;
  208. eq:=te_convert_l1;
  209. end;
  210. end;
  211. uvoid,
  212. pasbool,bool8bit,bool16bit,bool32bit,bool64bit:
  213. eq:=te_equal;
  214. else
  215. internalerror(200210061);
  216. end;
  217. end
  218. else
  219. begin
  220. if cdo_explicit in cdoptions then
  221. doconv:=basedefconvertsexplicit[basedeftbl[torddef(def_from).ordtype],basedeftbl[torddef(def_to).ordtype]]
  222. else
  223. doconv:=basedefconvertsimplicit[basedeftbl[torddef(def_from).ordtype],basedeftbl[torddef(def_to).ordtype]];
  224. if (doconv=tc_not_possible) then
  225. eq:=te_incompatible
  226. else if (not is_in_limit(def_from,def_to)) then
  227. { "punish" bad type conversions :) (JM) }
  228. eq:=te_convert_l3
  229. else
  230. eq:=te_convert_l1;
  231. end;
  232. end;
  233. enumdef :
  234. begin
  235. { needed for char(enum) }
  236. if cdo_explicit in cdoptions then
  237. begin
  238. doconv:=tc_int_2_int;
  239. eq:=te_convert_l1;
  240. end;
  241. end;
  242. floatdef :
  243. begin
  244. if is_currency(def_to) then
  245. begin
  246. doconv:=tc_real_2_currency;
  247. eq:=te_convert_l2;
  248. end;
  249. end;
  250. objectdef:
  251. begin
  252. if (m_delphi in current_settings.modeswitches) and
  253. is_class_or_interface_or_dispinterface_or_objc(def_from) and
  254. (cdo_explicit in cdoptions) then
  255. begin
  256. eq:=te_convert_l1;
  257. if (fromtreetype=niln) then
  258. begin
  259. { will be handled by the constant folding }
  260. doconv:=tc_equal;
  261. end
  262. else
  263. doconv:=tc_int_2_int;
  264. end;
  265. end;
  266. classrefdef,
  267. procvardef,
  268. pointerdef :
  269. begin
  270. if cdo_explicit in cdoptions then
  271. begin
  272. eq:=te_convert_l1;
  273. if (fromtreetype=niln) then
  274. begin
  275. { will be handled by the constant folding }
  276. doconv:=tc_equal;
  277. end
  278. else
  279. doconv:=tc_int_2_int;
  280. end;
  281. end;
  282. arraydef :
  283. begin
  284. if (m_mac in current_settings.modeswitches) and
  285. (fromtreetype=stringconstn) then
  286. begin
  287. eq:=te_convert_l3;
  288. doconv:=tc_cstring_2_int;
  289. end;
  290. end;
  291. end;
  292. end;
  293. stringdef :
  294. begin
  295. case def_from.typ of
  296. stringdef :
  297. begin
  298. { Constant string }
  299. if (fromtreetype=stringconstn) then
  300. begin
  301. if (tstringdef(def_from).stringtype=tstringdef(def_to).stringtype) then
  302. eq:=te_equal
  303. else
  304. begin
  305. doconv:=tc_string_2_string;
  306. { Don't prefer conversions from widestring to a
  307. normal string as we can loose information }
  308. if tstringdef(def_from).stringtype in [st_widestring,st_unicodestring] then
  309. eq:=te_convert_l3
  310. else if tstringdef(def_to).stringtype in [st_widestring,st_unicodestring] then
  311. eq:=te_convert_l2
  312. else
  313. eq:=te_equal;
  314. end;
  315. end
  316. else
  317. { Same string type, for shortstrings also the length must match }
  318. if (tstringdef(def_from).stringtype=tstringdef(def_to).stringtype) and
  319. ((tstringdef(def_from).stringtype<>st_shortstring) or
  320. (tstringdef(def_from).len=tstringdef(def_to).len)) then
  321. eq:=te_equal
  322. else
  323. begin
  324. doconv:=tc_string_2_string;
  325. case tstringdef(def_from).stringtype of
  326. st_widestring :
  327. begin
  328. { Prefer conversions to ansistring }
  329. if tstringdef(def_to).stringtype=st_ansistring then
  330. eq:=te_convert_l2
  331. else
  332. eq:=te_convert_l3;
  333. end;
  334. st_unicodestring :
  335. begin
  336. { Prefer conversions to ansistring }
  337. if tstringdef(def_to).stringtype=st_ansistring then
  338. eq:=te_convert_l2
  339. else
  340. eq:=te_convert_l3;
  341. end;
  342. st_shortstring :
  343. begin
  344. { Prefer shortstrings of different length or conversions
  345. from shortstring to ansistring }
  346. if (tstringdef(def_to).stringtype=st_shortstring) then
  347. eq:=te_convert_l1
  348. else if tstringdef(def_to).stringtype=st_ansistring then
  349. eq:=te_convert_l2
  350. else
  351. eq:=te_convert_l3;
  352. end;
  353. st_ansistring :
  354. begin
  355. { Prefer conversion to widestrings }
  356. if (tstringdef(def_to).stringtype in [st_widestring,st_unicodestring]) then
  357. eq:=te_convert_l2
  358. else
  359. eq:=te_convert_l3;
  360. end;
  361. end;
  362. end;
  363. end;
  364. orddef :
  365. begin
  366. { char to string}
  367. if is_char(def_from) or
  368. is_widechar(def_from) then
  369. begin
  370. doconv:=tc_char_2_string;
  371. eq:=te_convert_l1;
  372. end;
  373. end;
  374. arraydef :
  375. begin
  376. { array of char to string, the length check is done by the firstpass of this node }
  377. if is_chararray(def_from) or is_open_chararray(def_from) then
  378. begin
  379. { "Untyped" stringconstn is an array of char }
  380. if fromtreetype=stringconstn then
  381. begin
  382. doconv:=tc_string_2_string;
  383. { prefered string type depends on the $H switch }
  384. if not(cs_ansistrings in current_settings.localswitches) and
  385. (tstringdef(def_to).stringtype=st_shortstring) then
  386. eq:=te_equal
  387. else if (cs_ansistrings in current_settings.localswitches) and
  388. (tstringdef(def_to).stringtype=st_ansistring) then
  389. eq:=te_equal
  390. else if tstringdef(def_to).stringtype in [st_widestring,st_unicodestring] then
  391. eq:=te_convert_l3
  392. else
  393. eq:=te_convert_l1;
  394. end
  395. else
  396. begin
  397. doconv:=tc_chararray_2_string;
  398. if is_open_array(def_from) then
  399. begin
  400. if is_ansistring(def_to) then
  401. eq:=te_convert_l1
  402. else if is_widestring(def_to) or is_unicodestring(def_to) then
  403. eq:=te_convert_l3
  404. else
  405. eq:=te_convert_l2;
  406. end
  407. else
  408. begin
  409. if is_shortstring(def_to) then
  410. begin
  411. { Only compatible with arrays that fit
  412. smaller than 255 chars }
  413. if (def_from.size <= 255) then
  414. eq:=te_convert_l1;
  415. end
  416. else if is_ansistring(def_to) then
  417. begin
  418. if (def_from.size > 255) then
  419. eq:=te_convert_l1
  420. else
  421. eq:=te_convert_l2;
  422. end
  423. else if is_widestring(def_to) or is_unicodestring(def_to) then
  424. eq:=te_convert_l3
  425. else
  426. eq:=te_convert_l2;
  427. end;
  428. end;
  429. end
  430. else
  431. { array of widechar to string, the length check is done by the firstpass of this node }
  432. if is_widechararray(def_from) or is_open_widechararray(def_from) then
  433. begin
  434. doconv:=tc_chararray_2_string;
  435. if is_widestring(def_to) or is_unicodestring(def_to) then
  436. eq:=te_convert_l1
  437. else
  438. { size of widechar array is double due the sizeof a widechar }
  439. if not(is_shortstring(def_to) and (is_open_widechararray(def_from) or (def_from.size>255*sizeof(widechar)))) then
  440. eq:=te_convert_l3
  441. else
  442. eq:=te_convert_l2;
  443. end;
  444. end;
  445. pointerdef :
  446. begin
  447. { pchar can be assigned to short/ansistrings,
  448. but not in tp7 compatible mode }
  449. if not(m_tp7 in current_settings.modeswitches) then
  450. begin
  451. if is_pchar(def_from) then
  452. begin
  453. doconv:=tc_pchar_2_string;
  454. { prefer ansistrings because pchars can overflow shortstrings, }
  455. { but only if ansistrings are the default (JM) }
  456. if (is_shortstring(def_to) and
  457. not(cs_ansistrings in current_settings.localswitches)) or
  458. (is_ansistring(def_to) and
  459. (cs_ansistrings in current_settings.localswitches)) then
  460. eq:=te_convert_l1
  461. else
  462. eq:=te_convert_l2;
  463. end
  464. else if is_pwidechar(def_from) then
  465. begin
  466. doconv:=tc_pwchar_2_string;
  467. if is_widestring(def_to) or is_unicodestring(def_to) then
  468. eq:=te_convert_l1
  469. else
  470. eq:=te_convert_l3;
  471. end;
  472. end;
  473. end;
  474. objectdef :
  475. begin
  476. { corba interface -> id string }
  477. if is_interfacecorba(def_from) then
  478. begin
  479. doconv:=tc_intf_2_string;
  480. eq:=te_convert_l1;
  481. end;
  482. end;
  483. end;
  484. end;
  485. floatdef :
  486. begin
  487. case def_from.typ of
  488. orddef :
  489. begin { ordinal to real }
  490. { only for implicit and internal typecasts in tp/delphi }
  491. if (([cdo_explicit,cdo_internal] * cdoptions <> [cdo_explicit]) or
  492. ([m_tp7,m_delphi] * current_settings.modeswitches = [])) and
  493. (is_integer(def_from) or
  494. (is_currency(def_from) and
  495. (s64currencytype.typ = floatdef))) then
  496. begin
  497. doconv:=tc_int_2_real;
  498. eq:=te_convert_l4;
  499. end
  500. else if is_currency(def_from)
  501. { and (s64currencytype.typ = orddef)) } then
  502. begin
  503. { prefer conversion to orddef in this case, unless }
  504. { the orddef < currency (then it will get convert l3, }
  505. { and conversion to float is favoured) }
  506. doconv:=tc_int_2_real;
  507. eq:=te_convert_l2;
  508. end;
  509. end;
  510. floatdef :
  511. begin
  512. if tfloatdef(def_from).floattype=tfloatdef(def_to).floattype then
  513. eq:=te_equal
  514. else
  515. begin
  516. { Delphi does not allow explicit type conversions for float types like:
  517. single_var:=single(double_var);
  518. But if such conversion is inserted by compiler (internal) for some purpose,
  519. it should be allowed even in Delphi mode. }
  520. if (fromtreetype=realconstn) or
  521. not((cdoptions*[cdo_explicit,cdo_internal]=[cdo_explicit]) and
  522. (m_delphi in current_settings.modeswitches)) then
  523. begin
  524. doconv:=tc_real_2_real;
  525. { do we lose precision? }
  526. if def_to.size<def_from.size then
  527. eq:=te_convert_l2
  528. else
  529. eq:=te_convert_l1;
  530. end;
  531. end;
  532. end;
  533. end;
  534. end;
  535. enumdef :
  536. begin
  537. case def_from.typ of
  538. enumdef :
  539. begin
  540. if cdo_explicit in cdoptions then
  541. begin
  542. eq:=te_convert_l1;
  543. doconv:=tc_int_2_int;
  544. end
  545. else
  546. begin
  547. hd1:=def_from;
  548. while assigned(tenumdef(hd1).basedef) do
  549. hd1:=tenumdef(hd1).basedef;
  550. hd2:=def_to;
  551. while assigned(tenumdef(hd2).basedef) do
  552. hd2:=tenumdef(hd2).basedef;
  553. if (hd1=hd2) then
  554. begin
  555. eq:=te_convert_l1;
  556. { because of packenum they can have different sizes! (JM) }
  557. doconv:=tc_int_2_int;
  558. end
  559. else
  560. begin
  561. { assignment of an enum symbol to an unique type? }
  562. if (fromtreetype=ordconstn) and
  563. (tenumsym(tenumdef(hd1).getfirstsym)=tenumsym(tenumdef(hd2).getfirstsym)) then
  564. begin
  565. { because of packenum they can have different sizes! (JM) }
  566. eq:=te_convert_l1;
  567. doconv:=tc_int_2_int;
  568. end;
  569. end;
  570. end;
  571. end;
  572. orddef :
  573. begin
  574. if cdo_explicit in cdoptions then
  575. begin
  576. eq:=te_convert_l1;
  577. doconv:=tc_int_2_int;
  578. end;
  579. end;
  580. variantdef :
  581. begin
  582. eq:=te_convert_l1;
  583. doconv:=tc_variant_2_enum;
  584. end;
  585. pointerdef :
  586. begin
  587. { ugly, but delphi allows it }
  588. if (cdo_explicit in cdoptions) and
  589. (m_delphi in current_settings.modeswitches) then
  590. begin
  591. doconv:=tc_int_2_int;
  592. eq:=te_convert_l1;
  593. end;
  594. end;
  595. objectdef:
  596. begin
  597. { ugly, but delphi allows it }
  598. if (m_delphi in current_settings.modeswitches) and
  599. is_class_or_interface_or_dispinterface(def_from) and
  600. (cdo_explicit in cdoptions) then
  601. begin
  602. doconv:=tc_int_2_int;
  603. eq:=te_convert_l1;
  604. end;
  605. end;
  606. end;
  607. end;
  608. arraydef :
  609. begin
  610. { open array is also compatible with a single element of its base type.
  611. the extra check for deftyp is needed because equal defs can also return
  612. true if the def types are not the same, for example with dynarray to pointer. }
  613. if is_open_array(def_to) and
  614. (def_from.typ=tarraydef(def_to).elementdef.typ) and
  615. equal_defs(def_from,tarraydef(def_to).elementdef) then
  616. begin
  617. doconv:=tc_equal;
  618. eq:=te_convert_l1;
  619. end
  620. else
  621. begin
  622. case def_from.typ of
  623. arraydef :
  624. begin
  625. { from/to packed array -- packed chararrays are }
  626. { strings in ISO Pascal (at least if the lower bound }
  627. { is 1, but GPC makes all equal-length chararrays }
  628. { compatible), so treat those the same as regular }
  629. { char arrays }
  630. if (is_packed_array(def_from) and
  631. not is_chararray(def_from) and
  632. not is_widechararray(def_from)) xor
  633. (is_packed_array(def_to) and
  634. not is_chararray(def_to) and
  635. not is_widechararray(def_to)) then
  636. { both must be packed }
  637. begin
  638. compare_defs_ext:=te_incompatible;
  639. exit;
  640. end
  641. { to dynamic array }
  642. else if is_dynamic_array(def_to) then
  643. begin
  644. if equal_defs(tarraydef(def_from).elementdef,tarraydef(def_to).elementdef) then
  645. begin
  646. { dynamic array -> dynamic array }
  647. if is_dynamic_array(def_from) then
  648. eq:=te_equal
  649. { fpc modes only: array -> dyn. array }
  650. else if (current_settings.modeswitches*[m_objfpc,m_fpc]<>[]) and
  651. not(is_special_array(def_from)) and
  652. is_zero_based_array(def_from) then
  653. begin
  654. eq:=te_convert_l2;
  655. doconv:=tc_array_2_dynarray;
  656. end;
  657. end
  658. end
  659. else
  660. { to open array }
  661. if is_open_array(def_to) then
  662. begin
  663. { array constructor -> open array }
  664. if is_array_constructor(def_from) then
  665. begin
  666. if is_void(tarraydef(def_from).elementdef) then
  667. begin
  668. doconv:=tc_equal;
  669. eq:=te_convert_l1;
  670. end
  671. else
  672. begin
  673. subeq:=compare_defs_ext(tarraydef(def_from).elementdef,
  674. tarraydef(def_to).elementdef,
  675. { reason for cdo_allow_variant: see webtbs/tw7070a and webtbs/tw7070b }
  676. arrayconstructorn,hct,hpd,[cdo_check_operator,cdo_allow_variant]);
  677. if (subeq>=te_equal) then
  678. begin
  679. doconv:=tc_equal;
  680. eq:=te_convert_l1;
  681. end
  682. else
  683. if (subeq>te_incompatible) then
  684. begin
  685. doconv:=hct;
  686. eq:=te_convert_l2;
  687. end;
  688. end;
  689. end
  690. else
  691. { dynamic array -> open array }
  692. if is_dynamic_array(def_from) and
  693. equal_defs(tarraydef(def_from).elementdef,tarraydef(def_to).elementdef) then
  694. begin
  695. doconv:=tc_dynarray_2_openarray;
  696. eq:=te_convert_l2;
  697. end
  698. else
  699. { open array -> open array }
  700. if is_open_array(def_from) and
  701. equal_defs(tarraydef(def_from).elementdef,tarraydef(def_to).elementdef) then
  702. if tarraydef(def_from).elementdef=tarraydef(def_to).elementdef then
  703. eq:=te_exact
  704. else
  705. eq:=te_equal
  706. else
  707. { array -> open array }
  708. if not(cdo_parameter in cdoptions) and
  709. equal_defs(tarraydef(def_from).elementdef,tarraydef(def_to).elementdef) then
  710. begin
  711. if fromtreetype=stringconstn then
  712. eq:=te_convert_l1
  713. else
  714. eq:=te_equal;
  715. end;
  716. end
  717. else
  718. { to array of const }
  719. if is_array_of_const(def_to) then
  720. begin
  721. if is_array_of_const(def_from) or
  722. is_array_constructor(def_from) then
  723. begin
  724. eq:=te_equal;
  725. end
  726. else
  727. { array of tvarrec -> array of const }
  728. if equal_defs(tarraydef(def_to).elementdef,tarraydef(def_from).elementdef) then
  729. begin
  730. doconv:=tc_equal;
  731. eq:=te_convert_l1;
  732. end;
  733. end
  734. else
  735. { to array of char, from "Untyped" stringconstn (array of char) }
  736. if (fromtreetype=stringconstn) and
  737. (is_chararray(def_to) or
  738. is_widechararray(def_to)) then
  739. begin
  740. eq:=te_convert_l1;
  741. doconv:=tc_string_2_chararray;
  742. end
  743. else
  744. { other arrays }
  745. begin
  746. { open array -> array }
  747. if not(cdo_parameter in cdoptions) and
  748. is_open_array(def_from) and
  749. equal_defs(tarraydef(def_from).elementdef,tarraydef(def_to).elementdef) then
  750. begin
  751. eq:=te_equal
  752. end
  753. else
  754. { array -> array }
  755. if not(m_tp7 in current_settings.modeswitches) and
  756. not(m_delphi in current_settings.modeswitches) and
  757. (tarraydef(def_from).lowrange=tarraydef(def_to).lowrange) and
  758. (tarraydef(def_from).highrange=tarraydef(def_to).highrange) and
  759. equal_defs(tarraydef(def_from).elementdef,tarraydef(def_to).elementdef) and
  760. equal_defs(tarraydef(def_from).rangedef,tarraydef(def_to).rangedef) then
  761. begin
  762. eq:=te_equal
  763. end;
  764. end;
  765. end;
  766. pointerdef :
  767. begin
  768. { nil and voidpointers are compatible with dyn. arrays }
  769. if is_dynamic_array(def_to) and
  770. ((fromtreetype=niln) or
  771. is_voidpointer(def_from)) then
  772. begin
  773. doconv:=tc_equal;
  774. eq:=te_convert_l1;
  775. end
  776. else
  777. if is_zero_based_array(def_to) and
  778. equal_defs(tpointerdef(def_from).pointeddef,tarraydef(def_to).elementdef) then
  779. begin
  780. doconv:=tc_pointer_2_array;
  781. eq:=te_convert_l1;
  782. end;
  783. end;
  784. stringdef :
  785. begin
  786. { string to char array }
  787. if (not is_special_array(def_to)) and
  788. (is_char(tarraydef(def_to).elementdef)or
  789. is_widechar(tarraydef(def_to).elementdef)) then
  790. begin
  791. doconv:=tc_string_2_chararray;
  792. eq:=te_convert_l1;
  793. end;
  794. end;
  795. orddef:
  796. begin
  797. if is_chararray(def_to) and
  798. is_char(def_from) then
  799. begin
  800. doconv:=tc_char_2_chararray;
  801. eq:=te_convert_l2;
  802. end;
  803. end;
  804. recorddef :
  805. begin
  806. { tvarrec -> array of const }
  807. if is_array_of_const(def_to) and
  808. equal_defs(def_from,tarraydef(def_to).elementdef) then
  809. begin
  810. doconv:=tc_equal;
  811. eq:=te_convert_l1;
  812. end;
  813. end;
  814. variantdef :
  815. begin
  816. if is_dynamic_array(def_to) then
  817. begin
  818. doconv:=tc_variant_2_dynarray;
  819. eq:=te_convert_l1;
  820. end;
  821. end;
  822. end;
  823. end;
  824. end;
  825. variantdef :
  826. begin
  827. if (cdo_allow_variant in cdoptions) then
  828. begin
  829. case def_from.typ of
  830. enumdef :
  831. begin
  832. doconv:=tc_enum_2_variant;
  833. eq:=te_convert_l1;
  834. end;
  835. arraydef :
  836. begin
  837. if is_dynamic_array(def_from) then
  838. begin
  839. doconv:=tc_dynarray_2_variant;
  840. eq:=te_convert_l1;
  841. end;
  842. end;
  843. objectdef :
  844. begin
  845. if is_interface(def_from) then
  846. begin
  847. doconv:=tc_interface_2_variant;
  848. eq:=te_convert_l1;
  849. end;
  850. end;
  851. variantdef :
  852. begin
  853. { doing this in the compiler avoids a lot of unncessary
  854. copying }
  855. if (tvariantdef(def_from).varianttype=vt_olevariant) and
  856. (tvariantdef(def_to).varianttype=vt_normalvariant) then
  857. begin
  858. doconv:=tc_equal;
  859. eq:=te_convert_l1;
  860. end;
  861. end;
  862. end;
  863. end;
  864. end;
  865. pointerdef :
  866. begin
  867. case def_from.typ of
  868. stringdef :
  869. begin
  870. { string constant (which can be part of array constructor)
  871. to zero terminated string constant }
  872. if (fromtreetype = stringconstn) and
  873. (is_pchar(def_to) or is_pwidechar(def_to)) then
  874. begin
  875. doconv:=tc_cstring_2_pchar;
  876. eq:=te_convert_l2;
  877. end
  878. else
  879. if (cdo_explicit in cdoptions) or (fromtreetype = arrayconstructorn) then
  880. begin
  881. { pchar(ansistring) }
  882. if is_pchar(def_to) and
  883. is_ansistring(def_from) then
  884. begin
  885. doconv:=tc_ansistring_2_pchar;
  886. eq:=te_convert_l1;
  887. end
  888. else
  889. { pwidechar(widestring) }
  890. if is_pwidechar(def_to) and
  891. is_wide_or_unicode_string(def_from) then
  892. begin
  893. doconv:=tc_ansistring_2_pchar;
  894. eq:=te_convert_l1;
  895. end;
  896. end;
  897. end;
  898. orddef :
  899. begin
  900. { char constant to zero terminated string constant }
  901. if (fromtreetype in [ordconstn,arrayconstructorn]) then
  902. begin
  903. if (is_char(def_from) or is_widechar(def_from)) and
  904. (is_pchar(def_to) or is_pwidechar(def_to)) then
  905. begin
  906. doconv:=tc_cchar_2_pchar;
  907. eq:=te_convert_l1;
  908. end
  909. else
  910. if (m_delphi in current_settings.modeswitches) and is_integer(def_from) then
  911. begin
  912. doconv:=tc_cord_2_pointer;
  913. eq:=te_convert_l5;
  914. end;
  915. end;
  916. { allow explicit typecasts from ordinals to pointer.
  917. Support for delphi compatibility
  918. Support constructs like pointer(cardinal-cardinal) or pointer(longint+cardinal) where
  919. the result of the ordinal operation is int64 also on 32 bit platforms.
  920. It is also used by the compiler internally for inc(pointer,ordinal) }
  921. if (eq=te_incompatible) and
  922. not is_void(def_from) and
  923. (
  924. (
  925. (cdo_explicit in cdoptions) and
  926. (
  927. (m_delphi in current_settings.modeswitches) or
  928. { Don't allow pchar(char) in fpc modes }
  929. is_integer(def_from)
  930. )
  931. ) or
  932. (cdo_internal in cdoptions)
  933. ) then
  934. begin
  935. doconv:=tc_int_2_int;
  936. eq:=te_convert_l1;
  937. end;
  938. end;
  939. enumdef :
  940. begin
  941. { allow explicit typecasts from enums to pointer.
  942. Support for delphi compatibility
  943. }
  944. if (((cdo_explicit in cdoptions) and
  945. (m_delphi in current_settings.modeswitches)
  946. ) or
  947. (cdo_internal in cdoptions)
  948. ) then
  949. begin
  950. doconv:=tc_int_2_int;
  951. eq:=te_convert_l1;
  952. end;
  953. end;
  954. arraydef :
  955. begin
  956. { string constant (which can be part of array constructor)
  957. to zero terminated string constant }
  958. if (((fromtreetype = arrayconstructorn) and
  959. { can't use is_chararray, because returns false for }
  960. { array constructors }
  961. is_char(tarraydef(def_from).elementdef)) or
  962. (fromtreetype = stringconstn)) and
  963. (is_pchar(def_to) or is_pwidechar(def_to)) then
  964. begin
  965. doconv:=tc_cstring_2_pchar;
  966. eq:=te_convert_l2;
  967. end
  968. else
  969. { chararray to pointer }
  970. if (is_zero_based_array(def_from) or
  971. is_open_array(def_from)) and
  972. equal_defs(tarraydef(def_from).elementdef,tpointerdef(def_to).pointeddef) then
  973. begin
  974. doconv:=tc_array_2_pointer;
  975. { don't prefer the pchar overload when a constant
  976. string was passed }
  977. if fromtreetype=stringconstn then
  978. eq:=te_convert_l2
  979. else
  980. eq:=te_convert_l1;
  981. end
  982. else
  983. { dynamic array to pointer, delphi only }
  984. if (m_delphi in current_settings.modeswitches) and
  985. is_dynamic_array(def_from) and
  986. is_voidpointer(def_to) then
  987. begin
  988. eq:=te_equal;
  989. end;
  990. end;
  991. pointerdef :
  992. begin
  993. { check for far pointers }
  994. if (tpointerdef(def_from).is_far<>tpointerdef(def_to).is_far) then
  995. begin
  996. eq:=te_incompatible;
  997. end
  998. else
  999. { the types can be forward type, handle before normal type check !! }
  1000. if assigned(def_to.typesym) and
  1001. (tpointerdef(def_to).pointeddef.typ=forwarddef) then
  1002. begin
  1003. if (def_from.typesym=def_to.typesym) then
  1004. eq:=te_equal
  1005. end
  1006. else
  1007. { same types }
  1008. if equal_defs(tpointerdef(def_from).pointeddef,tpointerdef(def_to).pointeddef) then
  1009. begin
  1010. eq:=te_equal
  1011. end
  1012. else
  1013. { child class pointer can be assigned to anchestor pointers }
  1014. if (
  1015. (tpointerdef(def_from).pointeddef.typ=objectdef) and
  1016. (tpointerdef(def_to).pointeddef.typ=objectdef) and
  1017. tobjectdef(tpointerdef(def_from).pointeddef).is_related(
  1018. tobjectdef(tpointerdef(def_to).pointeddef))
  1019. ) then
  1020. begin
  1021. doconv:=tc_equal;
  1022. eq:=te_convert_l1;
  1023. end
  1024. else
  1025. { all pointers can be assigned to void-pointer }
  1026. if is_void(tpointerdef(def_to).pointeddef) then
  1027. begin
  1028. doconv:=tc_equal;
  1029. { give pwidechar,pchar a penalty so it prefers
  1030. conversion to ansistring }
  1031. if is_pchar(def_from) or
  1032. is_pwidechar(def_from) then
  1033. eq:=te_convert_l2
  1034. else
  1035. eq:=te_convert_l1;
  1036. end
  1037. else
  1038. { all pointers can be assigned from void-pointer }
  1039. if is_void(tpointerdef(def_from).pointeddef) or
  1040. { all pointers can be assigned from void-pointer or formaldef pointer, check
  1041. tw3777.pp if you change this }
  1042. (tpointerdef(def_from).pointeddef.typ=formaldef) then
  1043. begin
  1044. doconv:=tc_equal;
  1045. { give pwidechar a penalty so it prefers
  1046. conversion to pchar }
  1047. if is_pwidechar(def_to) then
  1048. eq:=te_convert_l2
  1049. else
  1050. eq:=te_convert_l1;
  1051. end
  1052. { id = generic class instance. metaclasses are also
  1053. class instances themselves. }
  1054. else if ((def_from=objc_idtype) and
  1055. (def_to=objc_metaclasstype)) or
  1056. ((def_to=objc_idtype) and
  1057. (def_from=objc_metaclasstype)) then
  1058. begin
  1059. doconv:=tc_equal;
  1060. eq:=te_convert_l2;
  1061. end;
  1062. end;
  1063. procvardef :
  1064. begin
  1065. { procedure variable can be assigned to an void pointer,
  1066. this is not allowed for complex procvars }
  1067. if (is_void(tpointerdef(def_to).pointeddef) or
  1068. (m_mac_procvar in current_settings.modeswitches)) and
  1069. tprocvardef(def_from).is_addressonly then
  1070. begin
  1071. doconv:=tc_equal;
  1072. eq:=te_convert_l1;
  1073. end;
  1074. end;
  1075. procdef :
  1076. begin
  1077. { procedure variable can be assigned to an void pointer,
  1078. this not allowed for methodpointers }
  1079. if (m_mac_procvar in current_settings.modeswitches) and
  1080. tprocdef(def_from).is_addressonly then
  1081. begin
  1082. doconv:=tc_proc_2_procvar;
  1083. eq:=te_convert_l2;
  1084. end;
  1085. end;
  1086. classrefdef,
  1087. objectdef :
  1088. begin
  1089. { class types and class reference type
  1090. can be assigned to void pointers, but it is less
  1091. preferred than assigning to a related objectdef }
  1092. if (
  1093. is_class_or_interface_or_dispinterface_or_objc(def_from) or
  1094. (def_from.typ=classrefdef)
  1095. ) and
  1096. (tpointerdef(def_to).pointeddef.typ=orddef) and
  1097. (torddef(tpointerdef(def_to).pointeddef).ordtype=uvoid) then
  1098. begin
  1099. doconv:=tc_equal;
  1100. eq:=te_convert_l2;
  1101. end
  1102. else if (is_objc_class_or_protocol(def_from) and
  1103. (def_to=objc_idtype)) or
  1104. { classrefs are also instances in Objective-C,
  1105. hence they're also assignment-cpmpatible with
  1106. id }
  1107. (is_objcclassref(def_from) and
  1108. ((def_to=objc_metaclasstype) or
  1109. (def_to=objc_idtype))) then
  1110. begin
  1111. doconv:=tc_equal;
  1112. eq:=te_convert_l2;
  1113. end;
  1114. end;
  1115. end;
  1116. end;
  1117. setdef :
  1118. begin
  1119. case def_from.typ of
  1120. setdef :
  1121. begin
  1122. if assigned(tsetdef(def_from).elementdef) and
  1123. assigned(tsetdef(def_to).elementdef) then
  1124. begin
  1125. { sets with the same element base type and the same range are equal }
  1126. if equal_defs(tsetdef(def_from).elementdef,tsetdef(def_to).elementdef) and
  1127. (tsetdef(def_from).setbase=tsetdef(def_to).setbase) and
  1128. (tsetdef(def_from).setmax=tsetdef(def_to).setmax) then
  1129. eq:=te_equal
  1130. else if is_subequal(tsetdef(def_from).elementdef,tsetdef(def_to).elementdef) then
  1131. begin
  1132. eq:=te_convert_l1;
  1133. doconv:=tc_set_to_set;
  1134. end;
  1135. end
  1136. else
  1137. begin
  1138. { empty set is compatible with everything }
  1139. eq:=te_convert_l1;
  1140. doconv:=tc_set_to_set;
  1141. end;
  1142. end;
  1143. arraydef :
  1144. begin
  1145. { automatic arrayconstructor -> set conversion }
  1146. if is_array_constructor(def_from) then
  1147. begin
  1148. doconv:=tc_arrayconstructor_2_set;
  1149. eq:=te_convert_l1;
  1150. end;
  1151. end;
  1152. end;
  1153. end;
  1154. procvardef :
  1155. begin
  1156. case def_from.typ of
  1157. procdef :
  1158. begin
  1159. { proc -> procvar }
  1160. if (m_tp_procvar in current_settings.modeswitches) or
  1161. (m_mac_procvar in current_settings.modeswitches) then
  1162. begin
  1163. subeq:=proc_to_procvar_equal(tprocdef(def_from),tprocvardef(def_to),cdo_warn_incompatible_univ in cdoptions);
  1164. if subeq>te_incompatible then
  1165. begin
  1166. doconv:=tc_proc_2_procvar;
  1167. if subeq>te_convert_l5 then
  1168. eq:=pred(subeq)
  1169. else
  1170. eq:=subeq;
  1171. end;
  1172. end;
  1173. end;
  1174. procvardef :
  1175. begin
  1176. { procvar -> procvar }
  1177. eq:=proc_to_procvar_equal(tprocvardef(def_from),tprocvardef(def_to),cdo_warn_incompatible_univ in cdoptions);
  1178. end;
  1179. pointerdef :
  1180. begin
  1181. { nil is compatible with procvars }
  1182. if (fromtreetype=niln) then
  1183. begin
  1184. if not Tprocvardef(def_to).is_addressonly then
  1185. {Nil to method pointers requires to convert a single
  1186. pointer nil value to a two pointer procvardef.}
  1187. doconv:=tc_nil_2_methodprocvar
  1188. else
  1189. doconv:=tc_equal;
  1190. eq:=te_convert_l1;
  1191. end
  1192. else
  1193. { for example delphi allows the assignement from pointers }
  1194. { to procedure variables }
  1195. if (m_pointer_2_procedure in current_settings.modeswitches) and
  1196. is_void(tpointerdef(def_from).pointeddef) and
  1197. tprocvardef(def_to).is_addressonly then
  1198. begin
  1199. doconv:=tc_equal;
  1200. eq:=te_convert_l1;
  1201. end;
  1202. end;
  1203. end;
  1204. end;
  1205. objectdef :
  1206. begin
  1207. { Objective-C classes (handle anonymous externals) }
  1208. if (def_from.typ=objectdef) and
  1209. (find_real_objcclass_definition(tobjectdef(def_from),false) =
  1210. find_real_objcclass_definition(tobjectdef(def_to),false)) then
  1211. begin
  1212. doconv:=tc_equal;
  1213. eq:=te_equal;
  1214. end
  1215. { object pascal objects }
  1216. else if (def_from.typ=objectdef) and
  1217. (tobjectdef(def_from).is_related(tobjectdef(def_to))) then
  1218. begin
  1219. doconv:=tc_equal;
  1220. eq:=te_convert_l1;
  1221. end
  1222. else
  1223. { Class/interface specific }
  1224. if is_class_or_interface_or_dispinterface_or_objc(def_to) then
  1225. begin
  1226. { void pointer also for delphi mode }
  1227. if (m_delphi in current_settings.modeswitches) and
  1228. is_voidpointer(def_from) then
  1229. begin
  1230. doconv:=tc_equal;
  1231. { prefer pointer-pointer assignments }
  1232. eq:=te_convert_l2;
  1233. end
  1234. else
  1235. { nil is compatible with class instances and interfaces }
  1236. if (fromtreetype=niln) then
  1237. begin
  1238. doconv:=tc_equal;
  1239. eq:=te_convert_l1;
  1240. end
  1241. { All Objective-C classes are compatible with ID }
  1242. else if is_objc_class_or_protocol(def_to) and
  1243. (def_from=objc_idtype) then
  1244. begin
  1245. doconv:=tc_equal;
  1246. eq:=te_convert_l2;
  1247. end
  1248. { classes can be assigned to interfaces
  1249. (same with objcclass and objcprotocol) }
  1250. else if ((is_interface(def_to) and
  1251. is_class(def_from)) or
  1252. (is_objcprotocol(def_to) and
  1253. is_objcclass(def_from))) and
  1254. assigned(tobjectdef(def_from).ImplementedInterfaces) then
  1255. begin
  1256. { we've to search in parent classes as well }
  1257. hobjdef:=tobjectdef(def_from);
  1258. while assigned(hobjdef) do
  1259. begin
  1260. if hobjdef.find_implemented_interface(tobjectdef(def_to))<>nil then
  1261. begin
  1262. if is_interface(def_to) then
  1263. doconv:=tc_class_2_intf
  1264. else
  1265. { for Objective-C, we don't have to do anything special }
  1266. doconv:=tc_equal;
  1267. { don't prefer this over objectdef->objectdef }
  1268. eq:=te_convert_l2;
  1269. break;
  1270. end;
  1271. hobjdef:=hobjdef.childof;
  1272. end;
  1273. end
  1274. { Interface 2 GUID handling }
  1275. else if (def_to=tdef(rec_tguid)) and
  1276. (fromtreetype=typen) and
  1277. is_interface(def_from) and
  1278. assigned(tobjectdef(def_from).iidguid) then
  1279. begin
  1280. eq:=te_convert_l1;
  1281. doconv:=tc_equal;
  1282. end
  1283. else if (def_from.typ=variantdef) and is_interface(def_to) then
  1284. begin
  1285. doconv:=tc_variant_2_interface;
  1286. eq:=te_convert_l2;
  1287. end
  1288. { ugly, but delphi allows it }
  1289. else if (def_from.typ in [orddef,enumdef]) and
  1290. (m_delphi in current_settings.modeswitches) and
  1291. (cdo_explicit in cdoptions) then
  1292. begin
  1293. doconv:=tc_int_2_int;
  1294. eq:=te_convert_l1;
  1295. end;
  1296. end;
  1297. end;
  1298. classrefdef :
  1299. begin
  1300. { similar to pointerdef wrt forwards }
  1301. if assigned(def_to.typesym) and
  1302. (tclassrefdef(def_to).pointeddef.typ=forwarddef) then
  1303. begin
  1304. if (def_from.typesym=def_to.typesym) then
  1305. eq:=te_equal;
  1306. end
  1307. else
  1308. { class reference types }
  1309. if (def_from.typ=classrefdef) then
  1310. begin
  1311. if equal_defs(tclassrefdef(def_from).pointeddef,tclassrefdef(def_to).pointeddef) then
  1312. begin
  1313. eq:=te_equal;
  1314. end
  1315. else
  1316. begin
  1317. doconv:=tc_equal;
  1318. if (cdo_explicit in cdoptions) or
  1319. tobjectdef(tclassrefdef(def_from).pointeddef).is_related(
  1320. tobjectdef(tclassrefdef(def_to).pointeddef)) then
  1321. eq:=te_convert_l1;
  1322. end;
  1323. end
  1324. else
  1325. if (m_delphi in current_settings.modeswitches) and
  1326. is_voidpointer(def_from) then
  1327. begin
  1328. doconv:=tc_equal;
  1329. { prefer pointer-pointer assignments }
  1330. eq:=te_convert_l2;
  1331. end
  1332. else
  1333. { nil is compatible with class references }
  1334. if (fromtreetype=niln) then
  1335. begin
  1336. doconv:=tc_equal;
  1337. eq:=te_convert_l1;
  1338. end
  1339. else
  1340. { id is compatible with all classref types }
  1341. if (def_from=objc_idtype) then
  1342. begin
  1343. doconv:=tc_equal;
  1344. eq:=te_convert_l1;
  1345. end;
  1346. end;
  1347. filedef :
  1348. begin
  1349. { typed files are all equal to the abstract file type
  1350. name TYPEDFILE in system.pp in is_equal in types.pas
  1351. the problem is that it sholud be also compatible to FILE
  1352. but this would leed to a problem for ASSIGN RESET and REWRITE
  1353. when trying to find the good overloaded function !!
  1354. so all file function are doubled in system.pp
  1355. this is not very beautiful !!}
  1356. if (def_from.typ=filedef) then
  1357. begin
  1358. if (tfiledef(def_from).filetyp=tfiledef(def_to).filetyp) then
  1359. begin
  1360. if
  1361. (
  1362. (tfiledef(def_from).typedfiledef=nil) and
  1363. (tfiledef(def_to).typedfiledef=nil)
  1364. ) or
  1365. (
  1366. (tfiledef(def_from).typedfiledef<>nil) and
  1367. (tfiledef(def_to).typedfiledef<>nil) and
  1368. equal_defs(tfiledef(def_from).typedfiledef,tfiledef(def_to).typedfiledef)
  1369. ) or
  1370. (
  1371. (tfiledef(def_from).filetyp = ft_typed) and
  1372. (tfiledef(def_to).filetyp = ft_typed) and
  1373. (
  1374. (tfiledef(def_from).typedfiledef = tdef(voidtype)) or
  1375. (tfiledef(def_to).typedfiledef = tdef(voidtype))
  1376. )
  1377. ) then
  1378. begin
  1379. eq:=te_equal;
  1380. end;
  1381. end
  1382. else
  1383. if ((tfiledef(def_from).filetyp = ft_untyped) and
  1384. (tfiledef(def_to).filetyp = ft_typed)) or
  1385. ((tfiledef(def_from).filetyp = ft_typed) and
  1386. (tfiledef(def_to).filetyp = ft_untyped)) then
  1387. begin
  1388. doconv:=tc_equal;
  1389. eq:=te_convert_l1;
  1390. end;
  1391. end;
  1392. end;
  1393. recorddef :
  1394. begin
  1395. { interface -> guid }
  1396. if (def_to=rec_tguid) and
  1397. (is_interfacecom(def_from) or is_dispinterface(def_from)) then
  1398. begin
  1399. doconv:=tc_intf_2_guid;
  1400. eq:=te_convert_l1;
  1401. end;
  1402. end;
  1403. formaldef :
  1404. begin
  1405. doconv:=tc_equal;
  1406. if (def_from.typ=formaldef) then
  1407. eq:=te_equal
  1408. else
  1409. { Just about everything can be converted to a formaldef...}
  1410. if not (def_from.typ in [abstractdef,errordef]) then
  1411. eq:=te_convert_l2;
  1412. end;
  1413. end;
  1414. { if we didn't find an appropriate type conversion yet
  1415. then we search also the := operator }
  1416. if (eq=te_incompatible) and
  1417. { make sure there is not a single variant if variants }
  1418. { are not allowed (otherwise if only cdo_check_operator }
  1419. { and e.g. fromdef=stringdef and todef=variantdef, then }
  1420. { the test will still succeed }
  1421. ((cdo_allow_variant in cdoptions) or
  1422. ((def_from.typ<>variantdef) and (def_to.typ<>variantdef))
  1423. ) and
  1424. (
  1425. { Check for variants? }
  1426. (
  1427. (cdo_allow_variant in cdoptions) and
  1428. ((def_from.typ=variantdef) or (def_to.typ=variantdef))
  1429. ) or
  1430. { Check for operators? }
  1431. (
  1432. (cdo_check_operator in cdoptions) and
  1433. ((def_from.typ in [objectdef,recorddef,arraydef,stringdef]) or
  1434. (def_to.typ in [objectdef,recorddef,arraydef,stringdef]))
  1435. )
  1436. ) then
  1437. begin
  1438. operatorpd:=search_assignment_operator(def_from,def_to);
  1439. if assigned(operatorpd) then
  1440. eq:=te_convert_operator;
  1441. end;
  1442. { update convtype for te_equal when it is not yet set }
  1443. if (eq=te_equal) and
  1444. (doconv=tc_not_possible) then
  1445. doconv:=tc_equal;
  1446. compare_defs_ext:=eq;
  1447. end;
  1448. function equal_defs(def_from,def_to:tdef):boolean;
  1449. var
  1450. convtyp : tconverttype;
  1451. pd : tprocdef;
  1452. begin
  1453. { Compare defs with nothingn and no explicit typecasts and
  1454. searching for overloaded operators is not needed }
  1455. equal_defs:=(compare_defs_ext(def_from,def_to,nothingn,convtyp,pd,[])>=te_equal);
  1456. end;
  1457. function compare_defs(def_from,def_to:tdef;fromtreetype:tnodetype):tequaltype;
  1458. var
  1459. doconv : tconverttype;
  1460. pd : tprocdef;
  1461. begin
  1462. compare_defs:=compare_defs_ext(def_from,def_to,fromtreetype,doconv,pd,[cdo_check_operator,cdo_allow_variant]);
  1463. end;
  1464. function is_subequal(def1, def2: tdef): boolean;
  1465. var
  1466. basedef1,basedef2 : tenumdef;
  1467. Begin
  1468. is_subequal := false;
  1469. if assigned(def1) and assigned(def2) then
  1470. Begin
  1471. if (def1.typ = orddef) and (def2.typ = orddef) then
  1472. Begin
  1473. { see p.47 of Turbo Pascal 7.01 manual for the separation of types }
  1474. { range checking for case statements is done with testrange }
  1475. case torddef(def1).ordtype of
  1476. u8bit,u16bit,u32bit,u64bit,
  1477. s8bit,s16bit,s32bit,s64bit :
  1478. is_subequal:=(torddef(def2).ordtype in [s64bit,u64bit,s32bit,u32bit,u8bit,s8bit,s16bit,u16bit]);
  1479. pasbool,bool8bit,bool16bit,bool32bit,bool64bit :
  1480. is_subequal:=(torddef(def2).ordtype in [pasbool,bool8bit,bool16bit,bool32bit,bool64bit]);
  1481. uchar :
  1482. is_subequal:=(torddef(def2).ordtype=uchar);
  1483. uwidechar :
  1484. is_subequal:=(torddef(def2).ordtype=uwidechar);
  1485. end;
  1486. end
  1487. else
  1488. Begin
  1489. { Check if both basedefs are equal }
  1490. if (def1.typ=enumdef) and (def2.typ=enumdef) then
  1491. Begin
  1492. { get both basedefs }
  1493. basedef1:=tenumdef(def1);
  1494. while assigned(basedef1.basedef) do
  1495. basedef1:=basedef1.basedef;
  1496. basedef2:=tenumdef(def2);
  1497. while assigned(basedef2.basedef) do
  1498. basedef2:=basedef2.basedef;
  1499. is_subequal:=(basedef1=basedef2);
  1500. end;
  1501. end;
  1502. end;
  1503. end;
  1504. function potentially_incompatible_univ_paras(def1, def2: tdef): boolean;
  1505. begin
  1506. result :=
  1507. { not entirely safe: different records can be passed differently
  1508. depending on the types of their fields, but they're hard to compare
  1509. (variant records, bitpacked vs non-bitpacked) }
  1510. ((def1.typ in [floatdef,recorddef,arraydef,filedef,variantdef]) and
  1511. (def1.typ<>def2.typ)) or
  1512. { pointers, ordinals and small sets are all passed the same}
  1513. (((def1.typ in [orddef,enumdef,pointerdef,procvardef,classrefdef]) or
  1514. (is_class_or_interface_or_objc(def1)) or
  1515. is_dynamic_array(def1) or
  1516. is_smallset(def1) or
  1517. is_ansistring(def1) or
  1518. is_unicodestring(def1)) <>
  1519. (def2.typ in [orddef,enumdef,pointerdef,procvardef,classrefdef]) or
  1520. (is_class_or_interface_or_objc(def2)) or
  1521. is_dynamic_array(def2) or
  1522. is_smallset(def2) or
  1523. is_ansistring(def2) or
  1524. is_unicodestring(def2)) or
  1525. { shortstrings }
  1526. (is_shortstring(def1)<>
  1527. is_shortstring(def2)) or
  1528. { winlike widestrings }
  1529. (is_widestring(def1)<>
  1530. is_widestring(def2)) or
  1531. { TP-style objects }
  1532. (is_object(def1) <>
  1533. is_object(def2));
  1534. end;
  1535. function compare_paras(para1,para2 : TFPObjectList; acp : tcompare_paras_type; cpoptions: tcompare_paras_options):tequaltype;
  1536. var
  1537. currpara1,
  1538. currpara2 : tparavarsym;
  1539. eq,lowesteq : tequaltype;
  1540. hpd : tprocdef;
  1541. convtype : tconverttype;
  1542. cdoptions : tcompare_defs_options;
  1543. i1,i2 : byte;
  1544. begin
  1545. compare_paras:=te_incompatible;
  1546. cdoptions:=[cdo_parameter,cdo_check_operator,cdo_allow_variant];
  1547. { we need to parse the list from left-right so the
  1548. not-default parameters are checked first }
  1549. lowesteq:=high(tequaltype);
  1550. i1:=0;
  1551. i2:=0;
  1552. if cpo_ignorehidden in cpoptions then
  1553. begin
  1554. while (i1<para1.count) and
  1555. (vo_is_hidden_para in tparavarsym(para1[i1]).varoptions) do
  1556. inc(i1);
  1557. while (i2<para2.count) and
  1558. (vo_is_hidden_para in tparavarsym(para2[i2]).varoptions) do
  1559. inc(i2);
  1560. end;
  1561. if cpo_ignoreframepointer in cpoptions then
  1562. begin
  1563. if (i1<para1.count) and
  1564. (vo_is_parentfp in tparavarsym(para1[i1]).varoptions) then
  1565. inc(i1);
  1566. if (i2<para2.count) and
  1567. (vo_is_parentfp in tparavarsym(para2[i2]).varoptions) then
  1568. inc(i2);
  1569. end;
  1570. while (i1<para1.count) and (i2<para2.count) do
  1571. begin
  1572. eq:=te_incompatible;
  1573. currpara1:=tparavarsym(para1[i1]);
  1574. currpara2:=tparavarsym(para2[i2]);
  1575. { Unique types must match exact }
  1576. if ((df_unique in currpara1.vardef.defoptions) or (df_unique in currpara2.vardef.defoptions)) and
  1577. (currpara1.vardef<>currpara2.vardef) then
  1578. exit;
  1579. { Handle hidden parameters separately, because self is
  1580. defined as voidpointer for methodpointers }
  1581. if (vo_is_hidden_para in currpara1.varoptions) or
  1582. (vo_is_hidden_para in currpara2.varoptions) then
  1583. begin
  1584. { both must be hidden }
  1585. if (vo_is_hidden_para in currpara1.varoptions)<>(vo_is_hidden_para in currpara2.varoptions) then
  1586. exit;
  1587. eq:=te_exact;
  1588. if not(vo_is_self in currpara1.varoptions) and
  1589. not(vo_is_self in currpara2.varoptions) then
  1590. begin
  1591. if not(cpo_ignorevarspez in cpoptions) and
  1592. (currpara1.varspez<>currpara2.varspez) then
  1593. exit;
  1594. eq:=compare_defs_ext(currpara1.vardef,currpara2.vardef,nothingn,
  1595. convtype,hpd,cdoptions);
  1596. end;
  1597. end
  1598. else
  1599. begin
  1600. case acp of
  1601. cp_value_equal_const :
  1602. begin
  1603. { this one is used for matching parameters from a call
  1604. statement to a procdef -> univ state can't be equal
  1605. in any case since the call statement does not contain
  1606. any information about that }
  1607. if (
  1608. not(cpo_ignorevarspez in cpoptions) and
  1609. (currpara1.varspez<>currpara2.varspez) and
  1610. ((currpara1.varspez in [vs_var,vs_out,vs_constref]) or
  1611. (currpara2.varspez in [vs_var,vs_out,vs_constref]))
  1612. ) then
  1613. exit;
  1614. eq:=compare_defs_ext(currpara1.vardef,currpara2.vardef,nothingn,
  1615. convtype,hpd,cdoptions);
  1616. end;
  1617. cp_all :
  1618. begin
  1619. { used to resolve forward definitions -> headers must
  1620. match exactly, including the "univ" specifier }
  1621. if (not(cpo_ignorevarspez in cpoptions) and
  1622. (currpara1.varspez<>currpara2.varspez)) or
  1623. (currpara1.univpara<>currpara2.univpara) then
  1624. exit;
  1625. eq:=compare_defs_ext(currpara1.vardef,currpara2.vardef,nothingn,
  1626. convtype,hpd,cdoptions);
  1627. end;
  1628. cp_procvar :
  1629. begin
  1630. if not(cpo_ignorevarspez in cpoptions) and
  1631. (currpara1.varspez<>currpara2.varspez) then
  1632. exit;
  1633. { "univ" state doesn't matter here: from univ to non-univ
  1634. matches if the types are compatible (i.e., as usual),
  1635. from from non-univ to univ also matches if the types
  1636. have the same size (checked below) }
  1637. eq:=compare_defs_ext(currpara1.vardef,currpara2.vardef,nothingn,
  1638. convtype,hpd,cdoptions);
  1639. { Parameters must be at least equal otherwise the are incompatible }
  1640. if (eq<te_equal) then
  1641. eq:=te_incompatible;
  1642. end;
  1643. else
  1644. eq:=compare_defs_ext(currpara1.vardef,currpara2.vardef,nothingn,
  1645. convtype,hpd,cdoptions);
  1646. end;
  1647. end;
  1648. { check type }
  1649. if eq=te_incompatible then
  1650. begin
  1651. { special case: "univ" parameters match if their size is equal }
  1652. if not(cpo_ignoreuniv in cpoptions) and
  1653. currpara2.univpara and
  1654. is_valid_univ_para_type(currpara1.vardef) and
  1655. (currpara1.vardef.size=currpara2.vardef.size) then
  1656. begin
  1657. { only pick as last choice }
  1658. eq:=te_convert_l5;
  1659. if (acp=cp_procvar) and
  1660. (cpo_warn_incompatible_univ in cpoptions) then
  1661. begin
  1662. { if the types may be passed in different ways by the
  1663. calling convention then this can lead to crashes
  1664. (note: not an exhaustive check, and failing this
  1665. this check does not mean things will crash on all
  1666. platforms) }
  1667. if potentially_incompatible_univ_paras(currpara1.vardef,currpara2.vardef) then
  1668. Message2(type_w_procvar_univ_conflicting_para,currpara1.vardef.typename,currpara2.vardef.typename)
  1669. end;
  1670. end
  1671. else
  1672. exit;
  1673. end;
  1674. { open strings can never match exactly, since you cannot define }
  1675. { a separate "open string" type -> we have to be able to }
  1676. { consider those as exact when resolving forward definitions. }
  1677. { The same goes for array of const. Open arrays are handled }
  1678. { already (if their element types match exactly, they are }
  1679. { considered to be an exact match) }
  1680. { And also for "inline defined" function parameter definitions }
  1681. { (i.e., function types directly declared in a parameter list) }
  1682. if (is_array_of_const(currpara1.vardef) or
  1683. is_open_string(currpara1.vardef) or
  1684. ((currpara1.vardef.typ = procvardef) and
  1685. not(assigned(currpara1.vardef.typesym)))) and
  1686. (eq=te_equal) and
  1687. (cpo_openequalisexact in cpoptions) then
  1688. eq:=te_exact;
  1689. if eq<lowesteq then
  1690. lowesteq:=eq;
  1691. { also check default value if both have it declared }
  1692. if (cpo_comparedefaultvalue in cpoptions) and
  1693. assigned(currpara1.defaultconstsym) and
  1694. assigned(currpara2.defaultconstsym) then
  1695. begin
  1696. if not equal_constsym(tconstsym(currpara1.defaultconstsym),tconstsym(currpara2.defaultconstsym)) then
  1697. exit;
  1698. end;
  1699. inc(i1);
  1700. inc(i2);
  1701. if cpo_ignorehidden in cpoptions then
  1702. begin
  1703. while (i1<para1.count) and
  1704. (vo_is_hidden_para in tparavarsym(para1[i1]).varoptions) do
  1705. inc(i1);
  1706. while (i2<para2.count) and
  1707. (vo_is_hidden_para in tparavarsym(para2[i2]).varoptions) do
  1708. inc(i2);
  1709. end;
  1710. if cpo_ignoreframepointer in cpoptions then
  1711. begin
  1712. if (i1<para1.count) and
  1713. (vo_is_parentfp in tparavarsym(para1[i1]).varoptions) then
  1714. inc(i1);
  1715. if (i2<para2.count) and
  1716. (vo_is_parentfp in tparavarsym(para2[i2]).varoptions) then
  1717. inc(i2);
  1718. end;
  1719. end;
  1720. { when both lists are empty then the parameters are equal. Also
  1721. when one list is empty and the other has a parameter with default
  1722. value assigned then the parameters are also equal }
  1723. if ((i1>=para1.count) and (i2>=para2.count)) or
  1724. ((cpo_allowdefaults in cpoptions) and
  1725. (((i1<para1.count) and assigned(tparavarsym(para1[i1]).defaultconstsym)) or
  1726. ((i2<para2.count) and assigned(tparavarsym(para2[i2]).defaultconstsym)))) then
  1727. compare_paras:=lowesteq;
  1728. end;
  1729. function proc_to_procvar_equal(def1:tabstractprocdef;def2:tprocvardef;checkincompatibleuniv: boolean):tequaltype;
  1730. var
  1731. eq : tequaltype;
  1732. po_comp : tprocoptions;
  1733. pa_comp: tcompare_paras_options;
  1734. begin
  1735. proc_to_procvar_equal:=te_incompatible;
  1736. if not(assigned(def1)) or not(assigned(def2)) then
  1737. exit;
  1738. { check for method pointer and local procedure pointer:
  1739. a) if one is a procedure of object, the other also has to be one
  1740. b) if one is a pure address, the other also has to be one
  1741. except if def1 is a global proc and def2 is a nested procdef
  1742. (global procedures can be converted into nested procvars)
  1743. c) if def1 is a nested procedure, then def2 has to be a nested
  1744. procvar and def1 has to have the po_delphi_nested_cc option
  1745. d) if def1 is a procvar, def1 and def2 both have to be nested or
  1746. non-nested (we don't allow assignments from non-nested to
  1747. nested procvars to make sure that we can still implement
  1748. nested procvars using trampolines -- e.g., this would be
  1749. necessary for LLVM or CIL as long as they do not have support
  1750. for Delphi-style frame pointer parameter passing) }
  1751. if (def1.is_methodpointer<>def2.is_methodpointer) or { a) }
  1752. ((def1.is_addressonly<>def2.is_addressonly) and { b) }
  1753. (is_nested_pd(def1) or
  1754. not is_nested_pd(def2))) or
  1755. ((def1.typ=procdef) and { c) }
  1756. is_nested_pd(def1) and
  1757. (not(po_delphi_nested_cc in def1.procoptions) or
  1758. not is_nested_pd(def2))) or
  1759. ((def1.typ=procvardef) and { d) }
  1760. (is_nested_pd(def1)<>is_nested_pd(def2))) then
  1761. exit;
  1762. pa_comp:=[cpo_ignoreframepointer];
  1763. if checkincompatibleuniv then
  1764. include(pa_comp,cpo_warn_incompatible_univ);
  1765. { check return value and options, methodpointer is already checked }
  1766. po_comp:=[po_staticmethod,po_interrupt,
  1767. po_iocheck,po_varargs];
  1768. if (m_delphi in current_settings.modeswitches) then
  1769. exclude(po_comp,po_varargs);
  1770. if (def1.proccalloption=def2.proccalloption) and
  1771. ((po_comp * def1.procoptions)= (po_comp * def2.procoptions)) and
  1772. equal_defs(def1.returndef,def2.returndef) then
  1773. begin
  1774. { return equal type based on the parameters, but a proc->procvar
  1775. is never exact, so map an exact match of the parameters to
  1776. te_equal }
  1777. eq:=compare_paras(def1.paras,def2.paras,cp_procvar,pa_comp);
  1778. if eq=te_exact then
  1779. eq:=te_equal;
  1780. if (eq=te_equal) then
  1781. begin
  1782. { prefer non-nested to non-nested over non-nested to nested }
  1783. if (is_nested_pd(def1)<>is_nested_pd(def2)) then
  1784. eq:=te_convert_l1;
  1785. end;
  1786. proc_to_procvar_equal:=eq;
  1787. end;
  1788. end;
  1789. function compatible_childmethod_resultdef(parentretdef, childretdef: tdef): boolean;
  1790. begin
  1791. compatible_childmethod_resultdef :=
  1792. (equal_defs(parentretdef,childretdef)) or
  1793. ((parentretdef.typ=objectdef) and
  1794. (childretdef.typ=objectdef) and
  1795. is_class_or_interface_or_objc(parentretdef) and
  1796. is_class_or_interface_or_objc(childretdef) and
  1797. (tobjectdef(childretdef).is_related(tobjectdef(parentretdef))))
  1798. end;
  1799. end.