defcmp.pas 59 KB

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