defcmp.pas 83 KB

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