2
0

defcmp.pas 84 KB

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