defcmp.pas 59 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. Compare definitions and parameter lists
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit defcmp;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. cclasses,
  23. globtype,globals,
  24. node,
  25. symconst,symtype,symdef;
  26. type
  27. { if acp is cp_all the var const or nothing are considered equal }
  28. tcompare_paras_type = ( cp_none, cp_value_equal_const, cp_all,cp_procvar);
  29. tcompare_paras_option = (cpo_allowdefaults,cpo_ignorehidden,cpo_allowconvert,cpo_comparedefaultvalue);
  30. tcompare_paras_options = set of tcompare_paras_option;
  31. tcompare_defs_option = (cdo_internal,cdo_explicit,cdo_check_operator,cdo_allow_variant);
  32. tcompare_defs_options = set of tcompare_defs_option;
  33. tconverttype = (tc_none,
  34. tc_equal,
  35. tc_not_possible,
  36. tc_string_2_string,
  37. tc_char_2_string,
  38. tc_char_2_chararray,
  39. tc_pchar_2_string,
  40. tc_cchar_2_pchar,
  41. tc_cstring_2_pchar,
  42. tc_ansistring_2_pchar,
  43. tc_string_2_chararray,
  44. tc_chararray_2_string,
  45. tc_array_2_pointer,
  46. tc_pointer_2_array,
  47. tc_int_2_int,
  48. tc_int_2_bool,
  49. tc_bool_2_bool,
  50. tc_bool_2_int,
  51. tc_real_2_real,
  52. tc_int_2_real,
  53. tc_real_2_currency,
  54. tc_proc_2_procvar,
  55. tc_arrayconstructor_2_set,
  56. tc_load_smallset,
  57. tc_cord_2_pointer,
  58. tc_intf_2_string,
  59. tc_intf_2_guid,
  60. tc_class_2_intf,
  61. tc_char_2_char,
  62. tc_normal_2_smallset,
  63. tc_dynarray_2_openarray,
  64. tc_pwchar_2_string,
  65. tc_variant_2_dynarray,
  66. tc_dynarray_2_variant,
  67. tc_variant_2_enum,
  68. tc_enum_2_variant,
  69. tc_interface_2_variant,
  70. tc_variant_2_interface,
  71. tc_array_2_dynarray
  72. );
  73. function compare_defs_ext(def_from,def_to : tdef;
  74. fromtreetype : tnodetype;
  75. var doconv : tconverttype;
  76. var operatorpd : tprocdef;
  77. cdoptions:tcompare_defs_options):tequaltype;
  78. { Returns if the type def_from can be converted to def_to or if both types are equal }
  79. function compare_defs(def_from,def_to:tdef;fromtreetype:tnodetype):tequaltype;
  80. { Returns true, if def1 and def2 are semantically the same }
  81. function equal_defs(def_from,def_to:tdef):boolean;
  82. { Checks for type compatibility (subgroups of type)
  83. used for case statements... probably missing stuff
  84. to use on other types }
  85. function is_subequal(def1, def2: tdef): boolean;
  86. {# true, if two parameter lists are equal
  87. if acp is cp_none, all have to match exactly
  88. if acp is cp_value_equal_const call by value
  89. and call by const parameter are assumed as
  90. equal
  91. allowdefaults indicates if default value parameters
  92. are allowed (in this case, the search order will first
  93. search for a routine with default parameters, before
  94. searching for the same definition with no parameters)
  95. }
  96. function compare_paras(para1,para2 : tlist; acp : tcompare_paras_type; cpoptions: tcompare_paras_options):tequaltype;
  97. { True if a function can be assigned to a procvar }
  98. { changed first argument type to pabstractprocdef so that it can also be }
  99. { used to test compatibility between two pprocvardefs (JM) }
  100. function proc_to_procvar_equal(def1:tabstractprocdef;def2:tprocvardef;methoderr:boolean):tequaltype;
  101. implementation
  102. uses
  103. verbose,systems,
  104. symtable,symsym,
  105. defutil,symutil;
  106. function compare_defs_ext(def_from,def_to : tdef;
  107. fromtreetype : tnodetype;
  108. var doconv : tconverttype;
  109. var operatorpd : tprocdef;
  110. cdoptions:tcompare_defs_options):tequaltype;
  111. { Tbasetype:
  112. uvoid,
  113. u8bit,u16bit,u32bit,u64bit,
  114. s8bit,s16bit,s32bit,s64bit,
  115. bool8bit,bool16bit,bool32bit,
  116. uchar,uwidechar }
  117. type
  118. tbasedef=(bvoid,bchar,bint,bbool);
  119. const
  120. basedeftbl:array[tbasetype] of tbasedef =
  121. (bvoid,
  122. bint,bint,bint,bint,
  123. bint,bint,bint,bint,
  124. bbool,bbool,bbool,
  125. bchar,bchar,bint);
  126. basedefconvertsimplicit : array[tbasedef,tbasedef] of tconverttype =
  127. { void, char, int, bool }
  128. ((tc_not_possible,tc_not_possible,tc_not_possible,tc_not_possible),
  129. (tc_not_possible,tc_char_2_char,tc_not_possible,tc_not_possible),
  130. (tc_not_possible,tc_not_possible,tc_int_2_int,tc_not_possible),
  131. (tc_not_possible,tc_not_possible,tc_not_possible,tc_bool_2_bool));
  132. basedefconvertsexplicit : array[tbasedef,tbasedef] of tconverttype =
  133. { void, char, int, bool }
  134. ((tc_not_possible,tc_not_possible,tc_not_possible,tc_not_possible),
  135. (tc_not_possible,tc_char_2_char,tc_int_2_int,tc_int_2_bool),
  136. (tc_not_possible,tc_int_2_int,tc_int_2_int,tc_int_2_bool),
  137. (tc_not_possible,tc_bool_2_int,tc_bool_2_int,tc_bool_2_bool));
  138. var
  139. subeq,eq : tequaltype;
  140. hd1,hd2 : tdef;
  141. hct : tconverttype;
  142. hd3 : tobjectdef;
  143. hpd : tprocdef;
  144. begin
  145. eq:=te_incompatible;
  146. doconv:=tc_not_possible;
  147. { safety check }
  148. if not(assigned(def_from) and assigned(def_to)) then
  149. begin
  150. compare_defs_ext:=te_incompatible;
  151. exit;
  152. end;
  153. { same def? then we've an exact match }
  154. if def_from=def_to then
  155. begin
  156. doconv:=tc_equal;
  157. compare_defs_ext:=te_exact;
  158. exit;
  159. end;
  160. { we walk the wanted (def_to) types and check then the def_from
  161. types if there is a conversion possible }
  162. case def_to.deftype of
  163. orddef :
  164. begin
  165. case def_from.deftype of
  166. orddef :
  167. begin
  168. if (torddef(def_from).typ=torddef(def_to).typ) then
  169. begin
  170. case torddef(def_from).typ of
  171. uchar,uwidechar,
  172. u8bit,u16bit,u32bit,u64bit,
  173. s8bit,s16bit,s32bit,s64bit:
  174. begin
  175. if (torddef(def_from).low=torddef(def_to).low) and
  176. (torddef(def_from).high=torddef(def_to).high) then
  177. eq:=te_equal
  178. else
  179. begin
  180. doconv:=tc_int_2_int;
  181. eq:=te_convert_l1;
  182. end;
  183. end;
  184. uvoid,
  185. bool8bit,bool16bit,bool32bit:
  186. eq:=te_equal;
  187. else
  188. internalerror(200210061);
  189. end;
  190. end
  191. else
  192. begin
  193. if cdo_explicit in cdoptions then
  194. doconv:=basedefconvertsexplicit[basedeftbl[torddef(def_from).typ],basedeftbl[torddef(def_to).typ]]
  195. else
  196. doconv:=basedefconvertsimplicit[basedeftbl[torddef(def_from).typ],basedeftbl[torddef(def_to).typ]];
  197. if (doconv=tc_not_possible) then
  198. eq:=te_incompatible
  199. else
  200. { "punish" bad type conversions :) (JM) }
  201. if (not is_in_limit(def_from,def_to)) and
  202. (def_from.size > def_to.size) then
  203. eq:=te_convert_l3
  204. else
  205. eq:=te_convert_l1;
  206. end;
  207. end;
  208. enumdef :
  209. begin
  210. { needed for char(enum) }
  211. if cdo_explicit in cdoptions then
  212. begin
  213. doconv:=tc_int_2_int;
  214. eq:=te_convert_l1;
  215. end;
  216. end;
  217. floatdef :
  218. begin
  219. if is_currency(def_to) then
  220. begin
  221. doconv:=tc_real_2_currency;
  222. eq:=te_convert_l2;
  223. end;
  224. end;
  225. classrefdef,
  226. procvardef,
  227. pointerdef :
  228. begin
  229. if cdo_explicit in cdoptions then
  230. begin
  231. eq:=te_convert_l1;
  232. if (fromtreetype=niln) then
  233. begin
  234. { will be handled by the constant folding }
  235. doconv:=tc_equal;
  236. end
  237. else
  238. doconv:=tc_int_2_int;
  239. end;
  240. end;
  241. end;
  242. end;
  243. stringdef :
  244. begin
  245. case def_from.deftype of
  246. stringdef :
  247. begin
  248. { Constant string }
  249. if (fromtreetype=stringconstn) then
  250. begin
  251. if (tstringdef(def_from).string_typ=tstringdef(def_to).string_typ) then
  252. eq:=te_equal
  253. else
  254. begin
  255. doconv:=tc_string_2_string;
  256. { Don't prefer conversions from widestring to a
  257. normal string as we can loose information }
  258. if tstringdef(def_from).string_typ=st_widestring then
  259. eq:=te_convert_l1
  260. else
  261. begin
  262. if tstringdef(def_to).string_typ=st_widestring then
  263. eq:=te_convert_l1
  264. else
  265. eq:=te_equal; { we can change the stringconst node }
  266. end;
  267. end;
  268. end
  269. else
  270. { Same string type, for shortstrings also the length must match }
  271. if (tstringdef(def_from).string_typ=tstringdef(def_to).string_typ) and
  272. ((tstringdef(def_from).string_typ<>st_shortstring) or
  273. (tstringdef(def_from).len=tstringdef(def_to).len)) then
  274. eq:=te_equal
  275. else
  276. begin
  277. doconv:=tc_string_2_string;
  278. { Prefer conversions to shortstring over other
  279. conversions. This is compatible with Delphi (PFV) }
  280. if tstringdef(def_to).string_typ=st_shortstring then
  281. eq:=te_convert_l2
  282. else
  283. eq:=te_convert_l3;
  284. end;
  285. end;
  286. orddef :
  287. begin
  288. { char to string}
  289. if is_char(def_from) or
  290. is_widechar(def_from) then
  291. begin
  292. doconv:=tc_char_2_string;
  293. eq:=te_convert_l1;
  294. end;
  295. end;
  296. arraydef :
  297. begin
  298. { array of char to string, the length check is done by the firstpass of this node }
  299. if is_chararray(def_from) or is_open_chararray(def_from) then
  300. begin
  301. doconv:=tc_chararray_2_string;
  302. if is_open_array(def_from) then
  303. begin
  304. if is_ansistring(def_to) then
  305. eq:=te_convert_l1
  306. else if is_widestring(def_to) then
  307. eq:=te_convert_l2
  308. else
  309. eq:=te_convert_l2;
  310. end
  311. else
  312. begin
  313. if is_shortstring(def_to) then
  314. begin
  315. { Only compatible with arrays that fit
  316. smaller than 255 chars }
  317. if (def_from.size <= 255) then
  318. eq:=te_convert_l1;
  319. end
  320. else if is_ansistring(def_to) then
  321. begin
  322. if (def_from.size > 255) then
  323. eq:=te_convert_l1
  324. else
  325. eq:=te_convert_l2;
  326. end
  327. else
  328. eq:=te_convert_l2;
  329. end;
  330. end
  331. else
  332. { array of widechar to string, the length check is done by the firstpass of this node }
  333. if is_widechararray(def_from) or is_open_widechararray(def_from) then
  334. begin
  335. doconv:=tc_chararray_2_string;
  336. if is_widestring(def_to) then
  337. eq:=te_convert_l1
  338. else
  339. { size of widechar array is double due the sizeof a widechar }
  340. if not(is_shortstring(def_to) and (def_from.size>255*sizeof(widechar))) then
  341. eq:=te_convert_l3;
  342. end;
  343. end;
  344. pointerdef :
  345. begin
  346. { pchar can be assigned to short/ansistrings,
  347. but not in tp7 compatible mode }
  348. if not(m_tp7 in aktmodeswitches) then
  349. begin
  350. if is_pchar(def_from) then
  351. begin
  352. doconv:=tc_pchar_2_string;
  353. { prefer ansistrings because pchars can overflow shortstrings, }
  354. { but only if ansistrings are the default (JM) }
  355. if (is_shortstring(def_to) and
  356. not(cs_ansistrings in aktlocalswitches)) or
  357. (is_ansistring(def_to) and
  358. (cs_ansistrings in aktlocalswitches)) then
  359. eq:=te_convert_l1
  360. else
  361. eq:=te_convert_l2;
  362. end
  363. else if is_pwidechar(def_from) then
  364. begin
  365. doconv:=tc_pwchar_2_string;
  366. if is_widestring(def_to) then
  367. eq:=te_convert_l1
  368. else
  369. eq:=te_convert_l3;
  370. end;
  371. end;
  372. end;
  373. end;
  374. end;
  375. floatdef :
  376. begin
  377. case def_from.deftype of
  378. orddef :
  379. begin { ordinal to real }
  380. if is_integer(def_from) or
  381. (is_currency(def_from) and
  382. (s64currencytype.def.deftype = floatdef)) then
  383. begin
  384. doconv:=tc_int_2_real;
  385. eq:=te_convert_l1;
  386. end
  387. else if is_currency(def_from)
  388. { and (s64currencytype.def.deftype = orddef)) } then
  389. begin
  390. { prefer conversion to orddef in this case, unless }
  391. { the orddef < currency (then it will get convert l3, }
  392. { and conversion to float is favoured) }
  393. doconv:=tc_int_2_real;
  394. eq:=te_convert_l2;
  395. end;
  396. end;
  397. floatdef :
  398. begin
  399. if tfloatdef(def_from).typ=tfloatdef(def_to).typ then
  400. eq:=te_equal
  401. else
  402. begin
  403. if (fromtreetype=realconstn) or
  404. not((cdo_explicit in cdoptions) and
  405. (m_delphi in aktmodeswitches)) then
  406. begin
  407. doconv:=tc_real_2_real;
  408. { do we loose precision? }
  409. if def_to.size<def_from.size then
  410. eq:=te_convert_l2
  411. else
  412. eq:=te_convert_l1;
  413. end;
  414. end;
  415. end;
  416. end;
  417. end;
  418. enumdef :
  419. begin
  420. case def_from.deftype of
  421. enumdef :
  422. begin
  423. if cdo_explicit in cdoptions then
  424. begin
  425. eq:=te_convert_l1;
  426. doconv:=tc_int_2_int;
  427. end
  428. else
  429. begin
  430. hd1:=def_from;
  431. while assigned(tenumdef(hd1).basedef) do
  432. hd1:=tenumdef(hd1).basedef;
  433. hd2:=def_to;
  434. while assigned(tenumdef(hd2).basedef) do
  435. hd2:=tenumdef(hd2).basedef;
  436. if (hd1=hd2) then
  437. begin
  438. eq:=te_convert_l1;
  439. { because of packenum they can have different sizes! (JM) }
  440. doconv:=tc_int_2_int;
  441. end
  442. else
  443. begin
  444. { assignment of an enum symbol to an unique type? }
  445. if (fromtreetype=ordconstn) and
  446. (tenumsym(tenumdef(hd1).firstenum)=tenumsym(tenumdef(hd2).firstenum)) then
  447. begin
  448. { because of packenum they can have different sizes! (JM) }
  449. eq:=te_convert_l1;
  450. doconv:=tc_int_2_int;
  451. end;
  452. end;
  453. end;
  454. end;
  455. orddef :
  456. begin
  457. if cdo_explicit in cdoptions then
  458. begin
  459. eq:=te_convert_l1;
  460. doconv:=tc_int_2_int;
  461. end;
  462. end;
  463. variantdef :
  464. begin
  465. eq:=te_convert_l1;
  466. doconv:=tc_variant_2_enum;
  467. end;
  468. pointerdef :
  469. begin
  470. { ugly, but delphi allows it }
  471. if (cdo_explicit in cdoptions) and
  472. (m_delphi in aktmodeswitches) and
  473. (eq=te_incompatible) then
  474. begin
  475. doconv:=tc_int_2_int;
  476. eq:=te_convert_l1;
  477. end;
  478. end;
  479. end;
  480. end;
  481. arraydef :
  482. begin
  483. { open array is also compatible with a single element of its base type }
  484. if is_open_array(def_to) and
  485. equal_defs(def_from,tarraydef(def_to).elementtype.def) then
  486. begin
  487. doconv:=tc_equal;
  488. eq:=te_convert_l1;
  489. end
  490. else
  491. begin
  492. case def_from.deftype of
  493. arraydef :
  494. begin
  495. { to dynamic array }
  496. if is_dynamic_array(def_to) then
  497. begin
  498. if equal_defs(tarraydef(def_from).elementtype.def,tarraydef(def_to).elementtype.def) then
  499. begin
  500. { dynamic array -> dynamic array }
  501. if is_dynamic_array(def_from) then
  502. eq:=te_equal
  503. { fpc modes only: array -> dyn. array }
  504. else if (aktmodeswitches*[m_objfpc,m_fpc]<>[]) and
  505. not(is_special_array(def_from)) and
  506. is_zero_based_array(def_from) then
  507. begin
  508. eq:=te_convert_l2;
  509. doconv:=tc_array_2_dynarray;
  510. end;
  511. end
  512. end
  513. else
  514. { to open array }
  515. if is_open_array(def_to) then
  516. begin
  517. { array constructor -> open array }
  518. if is_array_constructor(def_from) then
  519. begin
  520. if is_void(tarraydef(def_from).elementtype.def) then
  521. begin
  522. doconv:=tc_equal;
  523. eq:=te_convert_l1;
  524. end
  525. else
  526. begin
  527. subeq:=compare_defs_ext(tarraydef(def_from).elementtype.def,
  528. tarraydef(def_to).elementtype.def,
  529. arrayconstructorn,hct,hpd,[cdo_check_operator]);
  530. if (subeq>=te_equal) then
  531. begin
  532. doconv:=tc_equal;
  533. eq:=te_convert_l1;
  534. end
  535. else
  536. if (subeq>te_incompatible) then
  537. begin
  538. doconv:=hct;
  539. eq:=te_convert_l2;
  540. end;
  541. end;
  542. end
  543. else
  544. { dynamic array -> open array }
  545. if is_dynamic_array(def_from) and
  546. equal_defs(tarraydef(def_from).elementtype.def,tarraydef(def_to).elementtype.def) then
  547. begin
  548. doconv:=tc_dynarray_2_openarray;
  549. eq:=te_convert_l2;
  550. end
  551. else
  552. { array -> open array }
  553. if equal_defs(tarraydef(def_from).elementtype.def,tarraydef(def_to).elementtype.def) then
  554. eq:=te_equal;
  555. end
  556. else
  557. { to array of const }
  558. if is_array_of_const(def_to) then
  559. begin
  560. if is_array_of_const(def_from) or
  561. is_array_constructor(def_from) then
  562. begin
  563. eq:=te_equal;
  564. end
  565. else
  566. { array of tvarrec -> array of const }
  567. if equal_defs(tarraydef(def_to).elementtype.def,tarraydef(def_from).elementtype.def) then
  568. begin
  569. doconv:=tc_equal;
  570. eq:=te_convert_l1;
  571. end;
  572. end
  573. else
  574. { other arrays }
  575. begin
  576. { open array -> array }
  577. if is_open_array(def_from) and
  578. equal_defs(tarraydef(def_from).elementtype.def,tarraydef(def_to).elementtype.def) then
  579. begin
  580. eq:=te_equal
  581. end
  582. else
  583. { array -> array }
  584. if not(m_tp7 in aktmodeswitches) and
  585. not(m_delphi in aktmodeswitches) and
  586. (tarraydef(def_from).lowrange=tarraydef(def_to).lowrange) and
  587. (tarraydef(def_from).highrange=tarraydef(def_to).highrange) and
  588. equal_defs(tarraydef(def_from).elementtype.def,tarraydef(def_to).elementtype.def) and
  589. equal_defs(tarraydef(def_from).rangetype.def,tarraydef(def_to).rangetype.def) then
  590. begin
  591. eq:=te_equal
  592. end;
  593. end;
  594. end;
  595. pointerdef :
  596. begin
  597. { nil and voidpointers are compatible with dyn. arrays }
  598. if is_dynamic_array(def_to) and
  599. ((fromtreetype=niln) or
  600. is_voidpointer(def_from)) then
  601. begin
  602. doconv:=tc_equal;
  603. eq:=te_convert_l1;
  604. end
  605. else
  606. if is_zero_based_array(def_to) and
  607. equal_defs(tpointerdef(def_from).pointertype.def,tarraydef(def_to).elementtype.def) then
  608. begin
  609. doconv:=tc_pointer_2_array;
  610. eq:=te_convert_l1;
  611. end;
  612. end;
  613. stringdef :
  614. begin
  615. { string to char array }
  616. if (not is_special_array(def_to)) and
  617. (is_char(tarraydef(def_to).elementtype.def)or
  618. is_widechar(tarraydef(def_to).elementtype.def)) then
  619. begin
  620. doconv:=tc_string_2_chararray;
  621. eq:=te_convert_l1;
  622. end;
  623. end;
  624. orddef:
  625. begin
  626. if is_chararray(def_to) and
  627. is_char(def_from) then
  628. begin
  629. doconv:=tc_char_2_chararray;
  630. eq:=te_convert_l2;
  631. end;
  632. end;
  633. recorddef :
  634. begin
  635. { tvarrec -> array of const }
  636. if is_array_of_const(def_to) and
  637. equal_defs(def_from,tarraydef(def_to).elementtype.def) then
  638. begin
  639. doconv:=tc_equal;
  640. eq:=te_convert_l1;
  641. end;
  642. end;
  643. variantdef :
  644. begin
  645. if is_dynamic_array(def_to) then
  646. begin
  647. doconv:=tc_variant_2_dynarray;
  648. eq:=te_convert_l1;
  649. end;
  650. end;
  651. end;
  652. end;
  653. end;
  654. variantdef :
  655. begin
  656. if (cdo_allow_variant in cdoptions) then
  657. begin
  658. case def_from.deftype of
  659. enumdef :
  660. begin
  661. doconv:=tc_enum_2_variant;
  662. eq:=te_convert_l1;
  663. end;
  664. arraydef :
  665. begin
  666. if is_dynamic_array(def_from) then
  667. begin
  668. doconv:=tc_dynarray_2_variant;
  669. eq:=te_convert_l1;
  670. end;
  671. end;
  672. objectdef :
  673. begin
  674. if is_interface(def_from) then
  675. begin
  676. doconv:=tc_interface_2_variant;
  677. eq:=te_convert_l1;
  678. end;
  679. end;
  680. end;
  681. end;
  682. end;
  683. pointerdef :
  684. begin
  685. case def_from.deftype of
  686. stringdef :
  687. begin
  688. { string constant (which can be part of array constructor)
  689. to zero terminated string constant }
  690. if (fromtreetype in [arrayconstructorn,stringconstn]) and
  691. (is_pchar(def_to) or is_pwidechar(def_to)) then
  692. begin
  693. doconv:=tc_cstring_2_pchar;
  694. eq:=te_convert_l1;
  695. end
  696. else
  697. if cdo_explicit in cdoptions then
  698. begin
  699. { pchar(ansistring) }
  700. if is_pchar(def_to) and
  701. is_ansistring(def_from) then
  702. begin
  703. doconv:=tc_ansistring_2_pchar;
  704. eq:=te_convert_l1;
  705. end
  706. else
  707. { pwidechar(widestring) }
  708. if is_pwidechar(def_to) and
  709. is_widestring(def_from) then
  710. begin
  711. doconv:=tc_ansistring_2_pchar;
  712. eq:=te_convert_l1;
  713. end;
  714. end;
  715. end;
  716. orddef :
  717. begin
  718. { char constant to zero terminated string constant }
  719. if (fromtreetype=ordconstn) then
  720. begin
  721. if (is_char(def_from) or is_widechar(def_from)) and
  722. (is_pchar(def_to) or is_pwidechar(def_to)) then
  723. begin
  724. doconv:=tc_cchar_2_pchar;
  725. eq:=te_convert_l1;
  726. end
  727. else
  728. if (m_delphi in aktmodeswitches) and is_integer(def_from) then
  729. begin
  730. doconv:=tc_cord_2_pointer;
  731. eq:=te_convert_l1;
  732. end;
  733. end;
  734. { delphi compatible, allow explicit typecasts from
  735. ordinals to pointer.
  736. It is also used by the compiler internally for inc(pointer,ordinal) }
  737. if (eq=te_incompatible) and
  738. not is_void(def_from) and
  739. (
  740. (
  741. (m_delphi in aktmodeswitches) and
  742. (cdo_explicit in cdoptions)
  743. ) or
  744. (cdo_internal in cdoptions)
  745. ) then
  746. begin
  747. doconv:=tc_int_2_int;
  748. eq:=te_convert_l1;
  749. end;
  750. end;
  751. arraydef :
  752. begin
  753. { chararray to pointer }
  754. if (is_zero_based_array(def_from) or
  755. is_open_array(def_from)) and
  756. equal_defs(tarraydef(def_from).elementtype.def,tpointerdef(def_to).pointertype.def) then
  757. begin
  758. doconv:=tc_array_2_pointer;
  759. eq:=te_convert_l1;
  760. end
  761. else
  762. { dynamic array to pointer, delphi only }
  763. if (m_delphi in aktmodeswitches) and
  764. is_dynamic_array(def_from) then
  765. begin
  766. eq:=te_equal;
  767. end;
  768. end;
  769. pointerdef :
  770. begin
  771. { check for far pointers }
  772. if (tpointerdef(def_from).is_far<>tpointerdef(def_to).is_far) then
  773. begin
  774. eq:=te_incompatible;
  775. end
  776. else
  777. { the types can be forward type, handle before normal type check !! }
  778. if assigned(def_to.typesym) and
  779. (tpointerdef(def_to).pointertype.def.deftype=forwarddef) then
  780. begin
  781. if (def_from.typesym=def_to.typesym) then
  782. eq:=te_equal
  783. end
  784. else
  785. { same types }
  786. if equal_defs(tpointerdef(def_from).pointertype.def,tpointerdef(def_to).pointertype.def) then
  787. begin
  788. eq:=te_equal
  789. end
  790. else
  791. { child class pointer can be assigned to anchestor pointers }
  792. if (
  793. (tpointerdef(def_from).pointertype.def.deftype=objectdef) and
  794. (tpointerdef(def_to).pointertype.def.deftype=objectdef) and
  795. tobjectdef(tpointerdef(def_from).pointertype.def).is_related(
  796. tobjectdef(tpointerdef(def_to).pointertype.def))
  797. ) then
  798. begin
  799. doconv:=tc_equal;
  800. eq:=te_convert_l1;
  801. end
  802. else
  803. { all pointers can be assigned to void-pointer }
  804. if is_void(tpointerdef(def_to).pointertype.def) then
  805. begin
  806. doconv:=tc_equal;
  807. { give pwidechar,pchar a penalty so it prefers
  808. conversion to ansistring }
  809. if is_pchar(def_from) or
  810. is_pwidechar(def_from) then
  811. eq:=te_convert_l2
  812. else
  813. eq:=te_convert_l1;
  814. end
  815. else
  816. { all pointers can be assigned from void-pointer }
  817. if is_void(tpointerdef(def_from).pointertype.def) or
  818. { all pointers can be assigned from void-pointer or formaldef pointer, check
  819. tw3777.pp if you change this }
  820. (tpointerdef(def_from).pointertype.def.deftype=formaldef) then
  821. begin
  822. doconv:=tc_equal;
  823. { give pwidechar a penalty so it prefers
  824. conversion to pchar }
  825. if is_pwidechar(def_to) then
  826. eq:=te_convert_l2
  827. else
  828. eq:=te_convert_l1;
  829. end;
  830. end;
  831. procvardef :
  832. begin
  833. { procedure variable can be assigned to an void pointer,
  834. this not allowed for methodpointers }
  835. if is_void(tpointerdef(def_to).pointertype.def) and
  836. tprocvardef(def_from).is_addressonly then
  837. begin
  838. doconv:=tc_equal;
  839. eq:=te_convert_l1;
  840. end;
  841. end;
  842. classrefdef,
  843. objectdef :
  844. begin
  845. { class types and class reference type
  846. can be assigned to void pointers, but it is less
  847. preferred than assigning to a related objectdef }
  848. if (
  849. is_class_or_interface(def_from) or
  850. (def_from.deftype=classrefdef)
  851. ) and
  852. (tpointerdef(def_to).pointertype.def.deftype=orddef) and
  853. (torddef(tpointerdef(def_to).pointertype.def).typ=uvoid) then
  854. begin
  855. doconv:=tc_equal;
  856. eq:=te_convert_l2;
  857. end;
  858. end;
  859. end;
  860. end;
  861. setdef :
  862. begin
  863. case def_from.deftype of
  864. setdef :
  865. begin
  866. if assigned(tsetdef(def_from).elementtype.def) and
  867. assigned(tsetdef(def_to).elementtype.def) then
  868. begin
  869. { sets with the same element base type are equal }
  870. if is_subequal(tsetdef(def_from).elementtype.def,tsetdef(def_to).elementtype.def) then
  871. eq:=te_equal;
  872. end
  873. else
  874. { empty set is compatible with everything }
  875. eq:=te_equal;
  876. end;
  877. arraydef :
  878. begin
  879. { automatic arrayconstructor -> set conversion }
  880. if is_array_constructor(def_from) then
  881. begin
  882. doconv:=tc_arrayconstructor_2_set;
  883. eq:=te_convert_l1;
  884. end;
  885. end;
  886. end;
  887. end;
  888. procvardef :
  889. begin
  890. case def_from.deftype of
  891. procdef :
  892. begin
  893. { proc -> procvar }
  894. if (m_tp_procvar in aktmodeswitches) then
  895. begin
  896. subeq:=proc_to_procvar_equal(tprocdef(def_from),tprocvardef(def_to),true);
  897. if subeq>te_incompatible then
  898. begin
  899. doconv:=tc_proc_2_procvar;
  900. eq:=te_convert_l1;
  901. end;
  902. end;
  903. end;
  904. procvardef :
  905. begin
  906. { procvar -> procvar }
  907. eq:=proc_to_procvar_equal(tprocvardef(def_from),tprocvardef(def_to),false);
  908. end;
  909. pointerdef :
  910. begin
  911. { nil is compatible with procvars }
  912. if (fromtreetype=niln) then
  913. begin
  914. doconv:=tc_equal;
  915. eq:=te_convert_l1;
  916. end
  917. else
  918. { for example delphi allows the assignement from pointers }
  919. { to procedure variables }
  920. if (m_pointer_2_procedure in aktmodeswitches) and
  921. is_void(tpointerdef(def_from).pointertype.def) and
  922. tprocvardef(def_to).is_addressonly then
  923. begin
  924. doconv:=tc_equal;
  925. eq:=te_convert_l1;
  926. end;
  927. end;
  928. end;
  929. end;
  930. objectdef :
  931. begin
  932. { object pascal objects }
  933. if (def_from.deftype=objectdef) and
  934. (tobjectdef(def_from).is_related(tobjectdef(def_to))) then
  935. begin
  936. doconv:=tc_equal;
  937. eq:=te_convert_l1;
  938. end
  939. else
  940. { Class/interface specific }
  941. if is_class_or_interface(def_to) then
  942. begin
  943. { void pointer also for delphi mode }
  944. if (m_delphi in aktmodeswitches) and
  945. is_voidpointer(def_from) then
  946. begin
  947. doconv:=tc_equal;
  948. { prefer pointer-pointer assignments }
  949. eq:=te_convert_l2;
  950. end
  951. else
  952. { nil is compatible with class instances and interfaces }
  953. if (fromtreetype=niln) then
  954. begin
  955. doconv:=tc_equal;
  956. eq:=te_convert_l1;
  957. end
  958. { classes can be assigned to interfaces }
  959. else if is_interface(def_to) and
  960. is_class(def_from) and
  961. assigned(tobjectdef(def_from).implementedinterfaces) then
  962. begin
  963. { we've to search in parent classes as well }
  964. hd3:=tobjectdef(def_from);
  965. while assigned(hd3) do
  966. begin
  967. if hd3.implementedinterfaces.searchintf(def_to)<>-1 then
  968. begin
  969. doconv:=tc_class_2_intf;
  970. eq:=te_convert_l1;
  971. break;
  972. end;
  973. hd3:=hd3.childof;
  974. end;
  975. end
  976. { Interface 2 GUID handling }
  977. else if (def_to=tdef(rec_tguid)) and
  978. (fromtreetype=typen) and
  979. is_interface(def_from) and
  980. assigned(tobjectdef(def_from).iidguid) then
  981. begin
  982. eq:=te_convert_l1;
  983. doconv:=tc_equal;
  984. end
  985. else if (def_from.deftype=variantdef) and is_interface(def_to) then
  986. begin
  987. doconv:=tc_variant_2_interface;
  988. eq:=te_convert_l1;
  989. end
  990. { ugly, but delphi allows it }
  991. else if (eq=te_incompatible) and
  992. (def_from.deftype=orddef) and
  993. (m_delphi in aktmodeswitches) and
  994. (cdo_explicit in cdoptions) then
  995. begin
  996. doconv:=tc_int_2_int;
  997. eq:=te_convert_l1;
  998. end;
  999. end;
  1000. end;
  1001. classrefdef :
  1002. begin
  1003. { similar to pointerdef wrt forwards }
  1004. if assigned(def_to.typesym) and
  1005. (tclassrefdef(def_to).pointertype.def.deftype=forwarddef) then
  1006. begin
  1007. if (def_from.typesym=def_to.typesym) then
  1008. eq:=te_equal;
  1009. end
  1010. else
  1011. { class reference types }
  1012. if (def_from.deftype=classrefdef) then
  1013. begin
  1014. if equal_defs(tclassrefdef(def_from).pointertype.def,tclassrefdef(def_to).pointertype.def) then
  1015. begin
  1016. eq:=te_equal;
  1017. end
  1018. else
  1019. begin
  1020. doconv:=tc_equal;
  1021. if (cdo_explicit in cdoptions) or
  1022. tobjectdef(tclassrefdef(def_from).pointertype.def).is_related(
  1023. tobjectdef(tclassrefdef(def_to).pointertype.def)) then
  1024. eq:=te_convert_l1;
  1025. end;
  1026. end
  1027. else
  1028. { nil is compatible with class references }
  1029. if (fromtreetype=niln) then
  1030. begin
  1031. doconv:=tc_equal;
  1032. eq:=te_convert_l1;
  1033. end;
  1034. end;
  1035. filedef :
  1036. begin
  1037. { typed files are all equal to the abstract file type
  1038. name TYPEDFILE in system.pp in is_equal in types.pas
  1039. the problem is that it sholud be also compatible to FILE
  1040. but this would leed to a problem for ASSIGN RESET and REWRITE
  1041. when trying to find the good overloaded function !!
  1042. so all file function are doubled in system.pp
  1043. this is not very beautiful !!}
  1044. if (def_from.deftype=filedef) then
  1045. begin
  1046. if (tfiledef(def_from).filetyp=tfiledef(def_to).filetyp) then
  1047. begin
  1048. if
  1049. (
  1050. (tfiledef(def_from).typedfiletype.def=nil) and
  1051. (tfiledef(def_to).typedfiletype.def=nil)
  1052. ) or
  1053. (
  1054. (tfiledef(def_from).typedfiletype.def<>nil) and
  1055. (tfiledef(def_to).typedfiletype.def<>nil) and
  1056. equal_defs(tfiledef(def_from).typedfiletype.def,tfiledef(def_to).typedfiletype.def)
  1057. ) or
  1058. (
  1059. (tfiledef(def_from).filetyp = ft_typed) and
  1060. (tfiledef(def_to).filetyp = ft_typed) and
  1061. (
  1062. (tfiledef(def_from).typedfiletype.def = tdef(voidtype.def)) or
  1063. (tfiledef(def_to).typedfiletype.def = tdef(voidtype.def))
  1064. )
  1065. ) then
  1066. begin
  1067. eq:=te_equal;
  1068. end;
  1069. end
  1070. else
  1071. if ((tfiledef(def_from).filetyp = ft_untyped) and
  1072. (tfiledef(def_to).filetyp = ft_typed)) or
  1073. ((tfiledef(def_from).filetyp = ft_typed) and
  1074. (tfiledef(def_to).filetyp = ft_untyped)) then
  1075. begin
  1076. doconv:=tc_equal;
  1077. eq:=te_convert_l1;
  1078. end;
  1079. end;
  1080. end;
  1081. recorddef :
  1082. begin
  1083. { interface -> guid }
  1084. if is_interface(def_from) and
  1085. (def_to=rec_tguid) then
  1086. begin
  1087. doconv:=tc_intf_2_guid;
  1088. eq:=te_convert_l1;
  1089. end;
  1090. end;
  1091. formaldef :
  1092. begin
  1093. doconv:=tc_equal;
  1094. if (def_from.deftype=formaldef) then
  1095. eq:=te_equal
  1096. else
  1097. { Just about everything can be converted to a formaldef...}
  1098. if not (def_from.deftype in [abstractdef,errordef]) then
  1099. eq:=te_convert_l1;
  1100. end;
  1101. end;
  1102. { if we didn't find an appropriate type conversion yet
  1103. then we search also the := operator }
  1104. if (eq=te_incompatible) and
  1105. (
  1106. { Check for variants? }
  1107. (
  1108. (cdo_allow_variant in cdoptions) and
  1109. ((def_from.deftype=variantdef) or (def_to.deftype=variantdef))
  1110. ) or
  1111. { Check for operators? }
  1112. (
  1113. (cdo_check_operator in cdoptions) and
  1114. ((def_from.deftype in [objectdef,recorddef,arraydef,stringdef,variantdef]) or
  1115. (def_to.deftype in [objectdef,recorddef,arraydef,stringdef,variantdef]))
  1116. )
  1117. ) then
  1118. begin
  1119. operatorpd:=search_assignment_operator(def_from,def_to);
  1120. if assigned(operatorpd) then
  1121. eq:=te_convert_operator;
  1122. end;
  1123. { update convtype for te_equal when it is not yet set }
  1124. if (eq=te_equal) and
  1125. (doconv=tc_not_possible) then
  1126. doconv:=tc_equal;
  1127. compare_defs_ext:=eq;
  1128. end;
  1129. function equal_defs(def_from,def_to:tdef):boolean;
  1130. var
  1131. convtyp : tconverttype;
  1132. pd : tprocdef;
  1133. begin
  1134. { Compare defs with nothingn and no explicit typecasts and
  1135. searching for overloaded operators is not needed }
  1136. equal_defs:=(compare_defs_ext(def_from,def_to,nothingn,convtyp,pd,[])>=te_equal);
  1137. end;
  1138. function compare_defs(def_from,def_to:tdef;fromtreetype:tnodetype):tequaltype;
  1139. var
  1140. doconv : tconverttype;
  1141. pd : tprocdef;
  1142. begin
  1143. compare_defs:=compare_defs_ext(def_from,def_to,fromtreetype,doconv,pd,[cdo_check_operator,cdo_allow_variant]);
  1144. end;
  1145. function is_subequal(def1, def2: tdef): boolean;
  1146. var
  1147. basedef1,basedef2 : tenumdef;
  1148. Begin
  1149. is_subequal := false;
  1150. if assigned(def1) and assigned(def2) then
  1151. Begin
  1152. if (def1.deftype = orddef) and (def2.deftype = orddef) then
  1153. Begin
  1154. { see p.47 of Turbo Pascal 7.01 manual for the separation of types }
  1155. { range checking for case statements is done with testrange }
  1156. case torddef(def1).typ of
  1157. u8bit,u16bit,u32bit,u64bit,
  1158. s8bit,s16bit,s32bit,s64bit :
  1159. is_subequal:=(torddef(def2).typ in [s64bit,u64bit,s32bit,u32bit,u8bit,s8bit,s16bit,u16bit]);
  1160. bool8bit,bool16bit,bool32bit :
  1161. is_subequal:=(torddef(def2).typ in [bool8bit,bool16bit,bool32bit]);
  1162. uchar :
  1163. is_subequal:=(torddef(def2).typ=uchar);
  1164. uwidechar :
  1165. is_subequal:=(torddef(def2).typ=uwidechar);
  1166. end;
  1167. end
  1168. else
  1169. Begin
  1170. { Check if both basedefs are equal }
  1171. if (def1.deftype=enumdef) and (def2.deftype=enumdef) then
  1172. Begin
  1173. { get both basedefs }
  1174. basedef1:=tenumdef(def1);
  1175. while assigned(basedef1.basedef) do
  1176. basedef1:=basedef1.basedef;
  1177. basedef2:=tenumdef(def2);
  1178. while assigned(basedef2.basedef) do
  1179. basedef2:=basedef2.basedef;
  1180. is_subequal:=(basedef1=basedef2);
  1181. end;
  1182. end;
  1183. end;
  1184. end;
  1185. function compare_paras(para1,para2 : tlist; acp : tcompare_paras_type; cpoptions: tcompare_paras_options):tequaltype;
  1186. var
  1187. currpara1,
  1188. currpara2 : tparavarsym;
  1189. eq,lowesteq : tequaltype;
  1190. hpd : tprocdef;
  1191. convtype : tconverttype;
  1192. cdoptions : tcompare_defs_options;
  1193. i1,i2 : byte;
  1194. begin
  1195. compare_paras:=te_incompatible;
  1196. cdoptions:=[cdo_check_operator,cdo_allow_variant];
  1197. { we need to parse the list from left-right so the
  1198. not-default parameters are checked first }
  1199. lowesteq:=high(tequaltype);
  1200. i1:=0;
  1201. i2:=0;
  1202. if cpo_ignorehidden in cpoptions then
  1203. begin
  1204. while (i1<para1.count) and
  1205. (vo_is_hidden_para in tparavarsym(para1[i1]).varoptions) do
  1206. inc(i1);
  1207. while (i2<para2.count) and
  1208. (vo_is_hidden_para in tparavarsym(para2[i2]).varoptions) do
  1209. inc(i2);
  1210. end;
  1211. while (i1<para1.count) and (i2<para2.count) do
  1212. begin
  1213. eq:=te_incompatible;
  1214. currpara1:=tparavarsym(para1[i1]);
  1215. currpara2:=tparavarsym(para2[i2]);
  1216. { Unique types must match exact }
  1217. if ((df_unique in currpara1.vartype.def.defoptions) or (df_unique in currpara2.vartype.def.defoptions)) and
  1218. (currpara1.vartype.def<>currpara2.vartype.def) then
  1219. exit;
  1220. { Handle hidden parameters separately, because self is
  1221. defined as voidpointer for methodpointers }
  1222. if (vo_is_hidden_para in currpara1.varoptions) or
  1223. (vo_is_hidden_para in currpara2.varoptions) then
  1224. begin
  1225. { both must be hidden }
  1226. if (vo_is_hidden_para in currpara1.varoptions)<>(vo_is_hidden_para in currpara2.varoptions) then
  1227. exit;
  1228. eq:=te_equal;
  1229. if not(vo_is_self in currpara1.varoptions) and
  1230. not(vo_is_self in currpara2.varoptions) then
  1231. begin
  1232. if (currpara1.varspez<>currpara2.varspez) then
  1233. exit;
  1234. eq:=compare_defs_ext(currpara1.vartype.def,currpara2.vartype.def,nothingn,
  1235. convtype,hpd,cdoptions);
  1236. end;
  1237. end
  1238. else
  1239. begin
  1240. case acp of
  1241. cp_value_equal_const :
  1242. begin
  1243. if (
  1244. (currpara1.varspez<>currpara2.varspez) and
  1245. ((currpara1.varspez in [vs_var,vs_out]) or
  1246. (currpara2.varspez in [vs_var,vs_out]))
  1247. ) then
  1248. exit;
  1249. eq:=compare_defs_ext(currpara1.vartype.def,currpara2.vartype.def,nothingn,
  1250. convtype,hpd,cdoptions);
  1251. end;
  1252. cp_all :
  1253. begin
  1254. if (currpara1.varspez<>currpara2.varspez) then
  1255. exit;
  1256. eq:=compare_defs_ext(currpara1.vartype.def,currpara2.vartype.def,nothingn,
  1257. convtype,hpd,cdoptions);
  1258. end;
  1259. cp_procvar :
  1260. begin
  1261. if (currpara1.varspez<>currpara2.varspez) then
  1262. exit;
  1263. eq:=compare_defs_ext(currpara1.vartype.def,currpara2.vartype.def,nothingn,
  1264. convtype,hpd,cdoptions);
  1265. { Parameters must be at least equal otherwise the are incompatible }
  1266. if (eq<te_equal) then
  1267. eq:=te_incompatible;
  1268. end;
  1269. else
  1270. eq:=compare_defs_ext(currpara1.vartype.def,currpara2.vartype.def,nothingn,
  1271. convtype,hpd,cdoptions);
  1272. end;
  1273. end;
  1274. { check type }
  1275. if eq=te_incompatible then
  1276. exit;
  1277. if eq<lowesteq then
  1278. lowesteq:=eq;
  1279. { also check default value if both have it declared }
  1280. if (cpo_comparedefaultvalue in cpoptions) and
  1281. assigned(currpara1.defaultconstsym) and
  1282. assigned(currpara2.defaultconstsym) then
  1283. begin
  1284. if not equal_constsym(tconstsym(currpara1.defaultconstsym),tconstsym(currpara2.defaultconstsym)) then
  1285. exit;
  1286. end;
  1287. inc(i1);
  1288. inc(i2);
  1289. if cpo_ignorehidden in cpoptions then
  1290. begin
  1291. while (i1<para1.count) and
  1292. (vo_is_hidden_para in tparavarsym(para1[i1]).varoptions) do
  1293. inc(i1);
  1294. while (i2<para2.count) and
  1295. (vo_is_hidden_para in tparavarsym(para2[i2]).varoptions) do
  1296. inc(i2);
  1297. end;
  1298. end;
  1299. { when both lists are empty then the parameters are equal. Also
  1300. when one list is empty and the other has a parameter with default
  1301. value assigned then the parameters are also equal }
  1302. if ((i1>=para1.count) and (i2>=para2.count)) or
  1303. ((cpo_allowdefaults in cpoptions) and
  1304. (((i1<para1.count) and assigned(tparavarsym(para1[i1]).defaultconstsym)) or
  1305. ((i2<para2.count) and assigned(tparavarsym(para2[i2]).defaultconstsym)))) then
  1306. compare_paras:=lowesteq;
  1307. end;
  1308. function proc_to_procvar_equal(def1:tabstractprocdef;def2:tprocvardef;methoderr:boolean):tequaltype;
  1309. var
  1310. eq : tequaltype;
  1311. po_comp : tprocoptions;
  1312. begin
  1313. proc_to_procvar_equal:=te_incompatible;
  1314. if not(assigned(def1)) or not(assigned(def2)) then
  1315. exit;
  1316. { check for method pointer }
  1317. if (def1.is_methodpointer xor def2.is_methodpointer) or
  1318. (def1.is_addressonly xor def2.is_addressonly) then
  1319. begin
  1320. if methoderr then
  1321. Message(type_e_no_method_and_procedure_not_compatible);
  1322. exit;
  1323. end;
  1324. { check return value and options, methodpointer is already checked }
  1325. po_comp:=[po_staticmethod,po_interrupt,
  1326. po_iocheck,po_varargs];
  1327. if (m_delphi in aktmodeswitches) then
  1328. exclude(po_comp,po_varargs);
  1329. if (def1.proccalloption=def2.proccalloption) and
  1330. ((po_comp * def1.procoptions)= (po_comp * def2.procoptions)) and
  1331. equal_defs(def1.rettype.def,def2.rettype.def) then
  1332. begin
  1333. { return equal type based on the parameters, but a proc->procvar
  1334. is never exact, so map an exact match of the parameters to
  1335. te_equal }
  1336. eq:=compare_paras(def1.paras,def2.paras,cp_procvar,[]);
  1337. if eq=te_exact then
  1338. eq:=te_equal;
  1339. proc_to_procvar_equal:=eq;
  1340. end;
  1341. end;
  1342. end.
  1343. {
  1344. $Log$
  1345. Revision 1.73 2005-04-04 16:30:07 peter
  1346. * support open array to pointer
  1347. Revision 1.72 2005/03/28 15:19:18 peter
  1348. support (wide)char to pwidechar
  1349. Revision 1.71 2005/03/13 11:42:48 florian
  1350. + made @(<formaldef>) assignment compatible with all pointer types
  1351. Revision 1.70 2005/03/11 21:55:43 florian
  1352. + array -> dyn. array type cast
  1353. Revision 1.69 2005/02/14 17:13:06 peter
  1354. * truncate log
  1355. Revision 1.68 2005/02/03 19:24:33 florian
  1356. + support for another explicit ugly delphi type cast added
  1357. Revision 1.67 2005/02/02 19:04:31 florian
  1358. * <class/interface>(<any ord. type>) in delphi mode allowed
  1359. Revision 1.66 2005/01/10 22:10:26 peter
  1360. * widestring patches from Alexey Barkovoy
  1361. Revision 1.65 2005/01/07 21:14:21 florian
  1362. + compiler side of variant<->interface implemented
  1363. Revision 1.64 2005/01/06 13:30:40 florian
  1364. * widechararray patch from Peter
  1365. Revision 1.63 2005/01/03 17:55:57 florian
  1366. + first batch of patches to support tdef.getcopy fully
  1367. }