defcmp.pas 59 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431
  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) and
  722. is_pchar(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) and
  755. equal_defs(tarraydef(def_from).elementtype.def,tpointerdef(def_to).pointertype.def) then
  756. begin
  757. doconv:=tc_array_2_pointer;
  758. eq:=te_convert_l1;
  759. end
  760. else
  761. { dynamic array to pointer, delphi only }
  762. if (m_delphi in aktmodeswitches) and
  763. is_dynamic_array(def_from) then
  764. begin
  765. eq:=te_equal;
  766. end;
  767. end;
  768. pointerdef :
  769. begin
  770. { check for far pointers }
  771. if (tpointerdef(def_from).is_far<>tpointerdef(def_to).is_far) then
  772. begin
  773. eq:=te_incompatible;
  774. end
  775. else
  776. { the types can be forward type, handle before normal type check !! }
  777. if assigned(def_to.typesym) and
  778. (tpointerdef(def_to).pointertype.def.deftype=forwarddef) then
  779. begin
  780. if (def_from.typesym=def_to.typesym) then
  781. eq:=te_equal
  782. end
  783. else
  784. { same types }
  785. if equal_defs(tpointerdef(def_from).pointertype.def,tpointerdef(def_to).pointertype.def) then
  786. begin
  787. eq:=te_equal
  788. end
  789. else
  790. { child class pointer can be assigned to anchestor pointers }
  791. if (
  792. (tpointerdef(def_from).pointertype.def.deftype=objectdef) and
  793. (tpointerdef(def_to).pointertype.def.deftype=objectdef) and
  794. tobjectdef(tpointerdef(def_from).pointertype.def).is_related(
  795. tobjectdef(tpointerdef(def_to).pointertype.def))
  796. ) then
  797. begin
  798. doconv:=tc_equal;
  799. eq:=te_convert_l1;
  800. end
  801. else
  802. { all pointers can be assigned to void-pointer }
  803. if is_void(tpointerdef(def_to).pointertype.def) then
  804. begin
  805. doconv:=tc_equal;
  806. { give pwidechar,pchar a penalty so it prefers
  807. conversion to ansistring }
  808. if is_pchar(def_from) or
  809. is_pwidechar(def_from) then
  810. eq:=te_convert_l2
  811. else
  812. eq:=te_convert_l1;
  813. end
  814. else
  815. { all pointers can be assigned from void-pointer }
  816. if is_void(tpointerdef(def_from).pointertype.def) or
  817. { all pointers can be assigned from void-pointer or formaldef pointer, check
  818. tw3777.pp if you change this }
  819. (tpointerdef(def_from).pointertype.def.deftype=formaldef) then
  820. begin
  821. doconv:=tc_equal;
  822. { give pwidechar a penalty so it prefers
  823. conversion to pchar }
  824. if is_pwidechar(def_to) then
  825. eq:=te_convert_l2
  826. else
  827. eq:=te_convert_l1;
  828. end;
  829. end;
  830. procvardef :
  831. begin
  832. { procedure variable can be assigned to an void pointer,
  833. this not allowed for methodpointers }
  834. if is_void(tpointerdef(def_to).pointertype.def) and
  835. tprocvardef(def_from).is_addressonly then
  836. begin
  837. doconv:=tc_equal;
  838. eq:=te_convert_l1;
  839. end;
  840. end;
  841. classrefdef,
  842. objectdef :
  843. begin
  844. { class types and class reference type
  845. can be assigned to void pointers, but it is less
  846. preferred than assigning to a related objectdef }
  847. if (
  848. is_class_or_interface(def_from) or
  849. (def_from.deftype=classrefdef)
  850. ) and
  851. (tpointerdef(def_to).pointertype.def.deftype=orddef) and
  852. (torddef(tpointerdef(def_to).pointertype.def).typ=uvoid) then
  853. begin
  854. doconv:=tc_equal;
  855. eq:=te_convert_l2;
  856. end;
  857. end;
  858. end;
  859. end;
  860. setdef :
  861. begin
  862. case def_from.deftype of
  863. setdef :
  864. begin
  865. if assigned(tsetdef(def_from).elementtype.def) and
  866. assigned(tsetdef(def_to).elementtype.def) then
  867. begin
  868. { sets with the same element base type are equal }
  869. if is_subequal(tsetdef(def_from).elementtype.def,tsetdef(def_to).elementtype.def) then
  870. eq:=te_equal;
  871. end
  872. else
  873. { empty set is compatible with everything }
  874. eq:=te_equal;
  875. end;
  876. arraydef :
  877. begin
  878. { automatic arrayconstructor -> set conversion }
  879. if is_array_constructor(def_from) then
  880. begin
  881. doconv:=tc_arrayconstructor_2_set;
  882. eq:=te_convert_l1;
  883. end;
  884. end;
  885. end;
  886. end;
  887. procvardef :
  888. begin
  889. case def_from.deftype of
  890. procdef :
  891. begin
  892. { proc -> procvar }
  893. if (m_tp_procvar in aktmodeswitches) then
  894. begin
  895. subeq:=proc_to_procvar_equal(tprocdef(def_from),tprocvardef(def_to),true);
  896. if subeq>te_incompatible then
  897. begin
  898. doconv:=tc_proc_2_procvar;
  899. eq:=te_convert_l1;
  900. end;
  901. end;
  902. end;
  903. procvardef :
  904. begin
  905. { procvar -> procvar }
  906. eq:=proc_to_procvar_equal(tprocvardef(def_from),tprocvardef(def_to),false);
  907. end;
  908. pointerdef :
  909. begin
  910. { nil is compatible with procvars }
  911. if (fromtreetype=niln) then
  912. begin
  913. doconv:=tc_equal;
  914. eq:=te_convert_l1;
  915. end
  916. else
  917. { for example delphi allows the assignement from pointers }
  918. { to procedure variables }
  919. if (m_pointer_2_procedure in aktmodeswitches) and
  920. is_void(tpointerdef(def_from).pointertype.def) and
  921. tprocvardef(def_to).is_addressonly then
  922. begin
  923. doconv:=tc_equal;
  924. eq:=te_convert_l1;
  925. end;
  926. end;
  927. end;
  928. end;
  929. objectdef :
  930. begin
  931. { object pascal objects }
  932. if (def_from.deftype=objectdef) and
  933. (tobjectdef(def_from).is_related(tobjectdef(def_to))) then
  934. begin
  935. doconv:=tc_equal;
  936. eq:=te_convert_l1;
  937. end
  938. else
  939. { Class/interface specific }
  940. if is_class_or_interface(def_to) then
  941. begin
  942. { void pointer also for delphi mode }
  943. if (m_delphi in aktmodeswitches) and
  944. is_voidpointer(def_from) then
  945. begin
  946. doconv:=tc_equal;
  947. { prefer pointer-pointer assignments }
  948. eq:=te_convert_l2;
  949. end
  950. else
  951. { nil is compatible with class instances and interfaces }
  952. if (fromtreetype=niln) then
  953. begin
  954. doconv:=tc_equal;
  955. eq:=te_convert_l1;
  956. end
  957. { classes can be assigned to interfaces }
  958. else if is_interface(def_to) and
  959. is_class(def_from) and
  960. assigned(tobjectdef(def_from).implementedinterfaces) then
  961. begin
  962. { we've to search in parent classes as well }
  963. hd3:=tobjectdef(def_from);
  964. while assigned(hd3) do
  965. begin
  966. if hd3.implementedinterfaces.searchintf(def_to)<>-1 then
  967. begin
  968. doconv:=tc_class_2_intf;
  969. eq:=te_convert_l1;
  970. break;
  971. end;
  972. hd3:=hd3.childof;
  973. end;
  974. end
  975. { Interface 2 GUID handling }
  976. else if (def_to=tdef(rec_tguid)) and
  977. (fromtreetype=typen) and
  978. is_interface(def_from) and
  979. assigned(tobjectdef(def_from).iidguid) then
  980. begin
  981. eq:=te_convert_l1;
  982. doconv:=tc_equal;
  983. end
  984. else if (def_from.deftype=variantdef) and is_interface(def_to) then
  985. begin
  986. doconv:=tc_variant_2_interface;
  987. eq:=te_convert_l1;
  988. end
  989. { ugly, but delphi allows it }
  990. else if (eq=te_incompatible) and
  991. (def_from.deftype=orddef) and
  992. (m_delphi in aktmodeswitches) and
  993. (cdo_explicit in cdoptions) then
  994. begin
  995. doconv:=tc_int_2_int;
  996. eq:=te_convert_l1;
  997. end;
  998. end;
  999. end;
  1000. classrefdef :
  1001. begin
  1002. { similar to pointerdef wrt forwards }
  1003. if assigned(def_to.typesym) and
  1004. (tclassrefdef(def_to).pointertype.def.deftype=forwarddef) then
  1005. begin
  1006. if (def_from.typesym=def_to.typesym) then
  1007. eq:=te_equal;
  1008. end
  1009. else
  1010. { class reference types }
  1011. if (def_from.deftype=classrefdef) then
  1012. begin
  1013. if equal_defs(tclassrefdef(def_from).pointertype.def,tclassrefdef(def_to).pointertype.def) then
  1014. begin
  1015. eq:=te_equal;
  1016. end
  1017. else
  1018. begin
  1019. doconv:=tc_equal;
  1020. if (cdo_explicit in cdoptions) or
  1021. tobjectdef(tclassrefdef(def_from).pointertype.def).is_related(
  1022. tobjectdef(tclassrefdef(def_to).pointertype.def)) then
  1023. eq:=te_convert_l1;
  1024. end;
  1025. end
  1026. else
  1027. { nil is compatible with class references }
  1028. if (fromtreetype=niln) then
  1029. begin
  1030. doconv:=tc_equal;
  1031. eq:=te_convert_l1;
  1032. end;
  1033. end;
  1034. filedef :
  1035. begin
  1036. { typed files are all equal to the abstract file type
  1037. name TYPEDFILE in system.pp in is_equal in types.pas
  1038. the problem is that it sholud be also compatible to FILE
  1039. but this would leed to a problem for ASSIGN RESET and REWRITE
  1040. when trying to find the good overloaded function !!
  1041. so all file function are doubled in system.pp
  1042. this is not very beautiful !!}
  1043. if (def_from.deftype=filedef) then
  1044. begin
  1045. if (tfiledef(def_from).filetyp=tfiledef(def_to).filetyp) then
  1046. begin
  1047. if
  1048. (
  1049. (tfiledef(def_from).typedfiletype.def=nil) and
  1050. (tfiledef(def_to).typedfiletype.def=nil)
  1051. ) or
  1052. (
  1053. (tfiledef(def_from).typedfiletype.def<>nil) and
  1054. (tfiledef(def_to).typedfiletype.def<>nil) and
  1055. equal_defs(tfiledef(def_from).typedfiletype.def,tfiledef(def_to).typedfiletype.def)
  1056. ) or
  1057. (
  1058. (tfiledef(def_from).filetyp = ft_typed) and
  1059. (tfiledef(def_to).filetyp = ft_typed) and
  1060. (
  1061. (tfiledef(def_from).typedfiletype.def = tdef(voidtype.def)) or
  1062. (tfiledef(def_to).typedfiletype.def = tdef(voidtype.def))
  1063. )
  1064. ) then
  1065. begin
  1066. eq:=te_equal;
  1067. end;
  1068. end
  1069. else
  1070. if ((tfiledef(def_from).filetyp = ft_untyped) and
  1071. (tfiledef(def_to).filetyp = ft_typed)) or
  1072. ((tfiledef(def_from).filetyp = ft_typed) and
  1073. (tfiledef(def_to).filetyp = ft_untyped)) then
  1074. begin
  1075. doconv:=tc_equal;
  1076. eq:=te_convert_l1;
  1077. end;
  1078. end;
  1079. end;
  1080. recorddef :
  1081. begin
  1082. { interface -> guid }
  1083. if is_interface(def_from) and
  1084. (def_to=rec_tguid) then
  1085. begin
  1086. doconv:=tc_intf_2_guid;
  1087. eq:=te_convert_l1;
  1088. end;
  1089. end;
  1090. formaldef :
  1091. begin
  1092. doconv:=tc_equal;
  1093. if (def_from.deftype=formaldef) then
  1094. eq:=te_equal
  1095. else
  1096. { Just about everything can be converted to a formaldef...}
  1097. if not (def_from.deftype in [abstractdef,errordef]) then
  1098. eq:=te_convert_l1;
  1099. end;
  1100. end;
  1101. { if we didn't find an appropriate type conversion yet
  1102. then we search also the := operator }
  1103. if (eq=te_incompatible) and
  1104. (
  1105. { Check for variants? }
  1106. (
  1107. (cdo_allow_variant in cdoptions) and
  1108. ((def_from.deftype=variantdef) or (def_to.deftype=variantdef))
  1109. ) or
  1110. { Check for operators? }
  1111. (
  1112. (cdo_check_operator in cdoptions) and
  1113. ((def_from.deftype in [objectdef,recorddef,arraydef,stringdef,variantdef]) or
  1114. (def_to.deftype in [objectdef,recorddef,arraydef,stringdef,variantdef]))
  1115. )
  1116. ) then
  1117. begin
  1118. operatorpd:=search_assignment_operator(def_from,def_to);
  1119. if assigned(operatorpd) then
  1120. eq:=te_convert_operator;
  1121. end;
  1122. { update convtype for te_equal when it is not yet set }
  1123. if (eq=te_equal) and
  1124. (doconv=tc_not_possible) then
  1125. doconv:=tc_equal;
  1126. compare_defs_ext:=eq;
  1127. end;
  1128. function equal_defs(def_from,def_to:tdef):boolean;
  1129. var
  1130. convtyp : tconverttype;
  1131. pd : tprocdef;
  1132. begin
  1133. { Compare defs with nothingn and no explicit typecasts and
  1134. searching for overloaded operators is not needed }
  1135. equal_defs:=(compare_defs_ext(def_from,def_to,nothingn,convtyp,pd,[])>=te_equal);
  1136. end;
  1137. function compare_defs(def_from,def_to:tdef;fromtreetype:tnodetype):tequaltype;
  1138. var
  1139. doconv : tconverttype;
  1140. pd : tprocdef;
  1141. begin
  1142. compare_defs:=compare_defs_ext(def_from,def_to,fromtreetype,doconv,pd,[cdo_check_operator,cdo_allow_variant]);
  1143. end;
  1144. function is_subequal(def1, def2: tdef): boolean;
  1145. var
  1146. basedef1,basedef2 : tenumdef;
  1147. Begin
  1148. is_subequal := false;
  1149. if assigned(def1) and assigned(def2) then
  1150. Begin
  1151. if (def1.deftype = orddef) and (def2.deftype = orddef) then
  1152. Begin
  1153. { see p.47 of Turbo Pascal 7.01 manual for the separation of types }
  1154. { range checking for case statements is done with testrange }
  1155. case torddef(def1).typ of
  1156. u8bit,u16bit,u32bit,u64bit,
  1157. s8bit,s16bit,s32bit,s64bit :
  1158. is_subequal:=(torddef(def2).typ in [s64bit,u64bit,s32bit,u32bit,u8bit,s8bit,s16bit,u16bit]);
  1159. bool8bit,bool16bit,bool32bit :
  1160. is_subequal:=(torddef(def2).typ in [bool8bit,bool16bit,bool32bit]);
  1161. uchar :
  1162. is_subequal:=(torddef(def2).typ=uchar);
  1163. uwidechar :
  1164. is_subequal:=(torddef(def2).typ=uwidechar);
  1165. end;
  1166. end
  1167. else
  1168. Begin
  1169. { Check if both basedefs are equal }
  1170. if (def1.deftype=enumdef) and (def2.deftype=enumdef) then
  1171. Begin
  1172. { get both basedefs }
  1173. basedef1:=tenumdef(def1);
  1174. while assigned(basedef1.basedef) do
  1175. basedef1:=basedef1.basedef;
  1176. basedef2:=tenumdef(def2);
  1177. while assigned(basedef2.basedef) do
  1178. basedef2:=basedef2.basedef;
  1179. is_subequal:=(basedef1=basedef2);
  1180. end;
  1181. end;
  1182. end;
  1183. end;
  1184. function compare_paras(para1,para2 : tlist; acp : tcompare_paras_type; cpoptions: tcompare_paras_options):tequaltype;
  1185. var
  1186. currpara1,
  1187. currpara2 : tparavarsym;
  1188. eq,lowesteq : tequaltype;
  1189. hpd : tprocdef;
  1190. convtype : tconverttype;
  1191. cdoptions : tcompare_defs_options;
  1192. i1,i2 : byte;
  1193. begin
  1194. compare_paras:=te_incompatible;
  1195. cdoptions:=[cdo_check_operator,cdo_allow_variant];
  1196. { we need to parse the list from left-right so the
  1197. not-default parameters are checked first }
  1198. lowesteq:=high(tequaltype);
  1199. i1:=0;
  1200. i2:=0;
  1201. if cpo_ignorehidden in cpoptions then
  1202. begin
  1203. while (i1<para1.count) and
  1204. (vo_is_hidden_para in tparavarsym(para1[i1]).varoptions) do
  1205. inc(i1);
  1206. while (i2<para2.count) and
  1207. (vo_is_hidden_para in tparavarsym(para2[i2]).varoptions) do
  1208. inc(i2);
  1209. end;
  1210. while (i1<para1.count) and (i2<para2.count) do
  1211. begin
  1212. eq:=te_incompatible;
  1213. currpara1:=tparavarsym(para1[i1]);
  1214. currpara2:=tparavarsym(para2[i2]);
  1215. { Unique types must match exact }
  1216. if ((df_unique in currpara1.vartype.def.defoptions) or (df_unique in currpara2.vartype.def.defoptions)) and
  1217. (currpara1.vartype.def<>currpara2.vartype.def) then
  1218. exit;
  1219. { Handle hidden parameters separately, because self is
  1220. defined as voidpointer for methodpointers }
  1221. if (vo_is_hidden_para in currpara1.varoptions) or
  1222. (vo_is_hidden_para in currpara2.varoptions) then
  1223. begin
  1224. { both must be hidden }
  1225. if (vo_is_hidden_para in currpara1.varoptions)<>(vo_is_hidden_para in currpara2.varoptions) then
  1226. exit;
  1227. eq:=te_equal;
  1228. if not(vo_is_self in currpara1.varoptions) and
  1229. not(vo_is_self in currpara2.varoptions) then
  1230. begin
  1231. if (currpara1.varspez<>currpara2.varspez) then
  1232. exit;
  1233. eq:=compare_defs_ext(currpara1.vartype.def,currpara2.vartype.def,nothingn,
  1234. convtype,hpd,cdoptions);
  1235. end;
  1236. end
  1237. else
  1238. begin
  1239. case acp of
  1240. cp_value_equal_const :
  1241. begin
  1242. if (
  1243. (currpara1.varspez<>currpara2.varspez) and
  1244. ((currpara1.varspez in [vs_var,vs_out]) or
  1245. (currpara2.varspez in [vs_var,vs_out]))
  1246. ) then
  1247. exit;
  1248. eq:=compare_defs_ext(currpara1.vartype.def,currpara2.vartype.def,nothingn,
  1249. convtype,hpd,cdoptions);
  1250. end;
  1251. cp_all :
  1252. begin
  1253. if (currpara1.varspez<>currpara2.varspez) then
  1254. exit;
  1255. eq:=compare_defs_ext(currpara1.vartype.def,currpara2.vartype.def,nothingn,
  1256. convtype,hpd,cdoptions);
  1257. end;
  1258. cp_procvar :
  1259. begin
  1260. if (currpara1.varspez<>currpara2.varspez) then
  1261. exit;
  1262. eq:=compare_defs_ext(currpara1.vartype.def,currpara2.vartype.def,nothingn,
  1263. convtype,hpd,cdoptions);
  1264. { Parameters must be at least equal otherwise the are incompatible }
  1265. if (eq<te_equal) then
  1266. eq:=te_incompatible;
  1267. end;
  1268. else
  1269. eq:=compare_defs_ext(currpara1.vartype.def,currpara2.vartype.def,nothingn,
  1270. convtype,hpd,cdoptions);
  1271. end;
  1272. end;
  1273. { check type }
  1274. if eq=te_incompatible then
  1275. exit;
  1276. if eq<lowesteq then
  1277. lowesteq:=eq;
  1278. { also check default value if both have it declared }
  1279. if (cpo_comparedefaultvalue in cpoptions) and
  1280. assigned(currpara1.defaultconstsym) and
  1281. assigned(currpara2.defaultconstsym) then
  1282. begin
  1283. if not equal_constsym(tconstsym(currpara1.defaultconstsym),tconstsym(currpara2.defaultconstsym)) then
  1284. exit;
  1285. end;
  1286. inc(i1);
  1287. inc(i2);
  1288. if cpo_ignorehidden in cpoptions then
  1289. begin
  1290. while (i1<para1.count) and
  1291. (vo_is_hidden_para in tparavarsym(para1[i1]).varoptions) do
  1292. inc(i1);
  1293. while (i2<para2.count) and
  1294. (vo_is_hidden_para in tparavarsym(para2[i2]).varoptions) do
  1295. inc(i2);
  1296. end;
  1297. end;
  1298. { when both lists are empty then the parameters are equal. Also
  1299. when one list is empty and the other has a parameter with default
  1300. value assigned then the parameters are also equal }
  1301. if ((i1>=para1.count) and (i2>=para2.count)) or
  1302. ((cpo_allowdefaults in cpoptions) and
  1303. (((i1<para1.count) and assigned(tparavarsym(para1[i1]).defaultconstsym)) or
  1304. ((i2<para2.count) and assigned(tparavarsym(para2[i2]).defaultconstsym)))) then
  1305. compare_paras:=lowesteq;
  1306. end;
  1307. function proc_to_procvar_equal(def1:tabstractprocdef;def2:tprocvardef;methoderr:boolean):tequaltype;
  1308. var
  1309. eq : tequaltype;
  1310. po_comp : tprocoptions;
  1311. begin
  1312. proc_to_procvar_equal:=te_incompatible;
  1313. if not(assigned(def1)) or not(assigned(def2)) then
  1314. exit;
  1315. { check for method pointer }
  1316. if (def1.is_methodpointer xor def2.is_methodpointer) or
  1317. (def1.is_addressonly xor def2.is_addressonly) then
  1318. begin
  1319. if methoderr then
  1320. Message(type_e_no_method_and_procedure_not_compatible);
  1321. exit;
  1322. end;
  1323. { check return value and options, methodpointer is already checked }
  1324. po_comp:=[po_staticmethod,po_interrupt,
  1325. po_iocheck,po_varargs];
  1326. if (m_delphi in aktmodeswitches) then
  1327. exclude(po_comp,po_varargs);
  1328. if (def1.proccalloption=def2.proccalloption) and
  1329. ((po_comp * def1.procoptions)= (po_comp * def2.procoptions)) and
  1330. equal_defs(def1.rettype.def,def2.rettype.def) then
  1331. begin
  1332. { return equal type based on the parameters, but a proc->procvar
  1333. is never exact, so map an exact match of the parameters to
  1334. te_equal }
  1335. eq:=compare_paras(def1.paras,def2.paras,cp_procvar,[]);
  1336. if eq=te_exact then
  1337. eq:=te_equal;
  1338. proc_to_procvar_equal:=eq;
  1339. end;
  1340. end;
  1341. end.
  1342. {
  1343. $Log$
  1344. Revision 1.71 2005-03-13 11:42:48 florian
  1345. + made @(<formaldef>) assignment compatible with all pointer types
  1346. Revision 1.70 2005/03/11 21:55:43 florian
  1347. + array -> dyn. array type cast
  1348. Revision 1.69 2005/02/14 17:13:06 peter
  1349. * truncate log
  1350. Revision 1.68 2005/02/03 19:24:33 florian
  1351. + support for another explicit ugly delphi type cast added
  1352. Revision 1.67 2005/02/02 19:04:31 florian
  1353. * <class/interface>(<any ord. type>) in delphi mode allowed
  1354. Revision 1.66 2005/01/10 22:10:26 peter
  1355. * widestring patches from Alexey Barkovoy
  1356. Revision 1.65 2005/01/07 21:14:21 florian
  1357. + compiler side of variant<->interface implemented
  1358. Revision 1.64 2005/01/06 13:30:40 florian
  1359. * widechararray patch from Peter
  1360. Revision 1.63 2005/01/03 17:55:57 florian
  1361. + first batch of patches to support tdef.getcopy fully
  1362. }