defcmp.pas 84 KB

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