defcmp.pas 84 KB

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