defcmp.pas 83 KB

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