defcmp.pas 84 KB

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