defcmp.pas 60 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466
  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. pointerdef :
  468. begin
  469. { ugly, but delphi allows it }
  470. if (cdo_explicit in cdoptions) and
  471. (m_delphi in aktmodeswitches) and
  472. (eq=te_incompatible) then
  473. begin
  474. doconv:=tc_int_2_int;
  475. eq:=te_convert_l1;
  476. end;
  477. end;
  478. end;
  479. end;
  480. arraydef :
  481. begin
  482. { open array is also compatible with a single element of its base type }
  483. if is_open_array(def_to) and
  484. equal_defs(def_from,tarraydef(def_to).elementtype.def) then
  485. begin
  486. doconv:=tc_equal;
  487. eq:=te_convert_l1;
  488. end
  489. else
  490. begin
  491. case def_from.deftype of
  492. arraydef :
  493. begin
  494. { to dynamic array }
  495. if is_dynamic_array(def_to) then
  496. begin
  497. { dynamic array -> dynamic array }
  498. if is_dynamic_array(def_from) and
  499. equal_defs(tarraydef(def_from).elementtype.def,tarraydef(def_to).elementtype.def) then
  500. eq:=te_equal;
  501. end
  502. else
  503. { to open array }
  504. if is_open_array(def_to) then
  505. begin
  506. { array constructor -> open array }
  507. if is_array_constructor(def_from) then
  508. begin
  509. if is_void(tarraydef(def_from).elementtype.def) then
  510. begin
  511. doconv:=tc_equal;
  512. eq:=te_convert_l1;
  513. end
  514. else
  515. begin
  516. subeq:=compare_defs_ext(tarraydef(def_from).elementtype.def,
  517. tarraydef(def_to).elementtype.def,
  518. arrayconstructorn,hct,hpd,[cdo_check_operator]);
  519. if (subeq>=te_equal) then
  520. begin
  521. doconv:=tc_equal;
  522. eq:=te_convert_l1;
  523. end
  524. else
  525. if (subeq>te_incompatible) then
  526. begin
  527. doconv:=hct;
  528. eq:=te_convert_l2;
  529. end;
  530. end;
  531. end
  532. else
  533. { dynamic array -> open array }
  534. if is_dynamic_array(def_from) and
  535. equal_defs(tarraydef(def_from).elementtype.def,tarraydef(def_to).elementtype.def) then
  536. begin
  537. doconv:=tc_dynarray_2_openarray;
  538. eq:=te_convert_l2;
  539. end
  540. else
  541. { array -> open array }
  542. if equal_defs(tarraydef(def_from).elementtype.def,tarraydef(def_to).elementtype.def) then
  543. eq:=te_equal;
  544. end
  545. else
  546. { to array of const }
  547. if is_array_of_const(def_to) then
  548. begin
  549. if is_array_of_const(def_from) or
  550. is_array_constructor(def_from) then
  551. begin
  552. eq:=te_equal;
  553. end
  554. else
  555. { array of tvarrec -> array of const }
  556. if equal_defs(tarraydef(def_to).elementtype.def,tarraydef(def_from).elementtype.def) then
  557. begin
  558. doconv:=tc_equal;
  559. eq:=te_convert_l1;
  560. end;
  561. end
  562. else
  563. { other arrays }
  564. begin
  565. { open array -> array }
  566. if is_open_array(def_from) and
  567. equal_defs(tarraydef(def_from).elementtype.def,tarraydef(def_to).elementtype.def) then
  568. begin
  569. eq:=te_equal
  570. end
  571. else
  572. { array -> array }
  573. if not(m_tp7 in aktmodeswitches) and
  574. not(m_delphi in aktmodeswitches) and
  575. (tarraydef(def_from).lowrange=tarraydef(def_to).lowrange) and
  576. (tarraydef(def_from).highrange=tarraydef(def_to).highrange) and
  577. equal_defs(tarraydef(def_from).elementtype.def,tarraydef(def_to).elementtype.def) and
  578. equal_defs(tarraydef(def_from).rangetype.def,tarraydef(def_to).rangetype.def) then
  579. begin
  580. eq:=te_equal
  581. end;
  582. end;
  583. end;
  584. pointerdef :
  585. begin
  586. { nil and voidpointers are compatible with dyn. arrays }
  587. if is_dynamic_array(def_to) and
  588. ((fromtreetype=niln) or
  589. is_voidpointer(def_from)) then
  590. begin
  591. doconv:=tc_equal;
  592. eq:=te_convert_l1;
  593. end
  594. else
  595. if is_zero_based_array(def_to) and
  596. equal_defs(tpointerdef(def_from).pointertype.def,tarraydef(def_to).elementtype.def) then
  597. begin
  598. doconv:=tc_pointer_2_array;
  599. eq:=te_convert_l1;
  600. end;
  601. end;
  602. stringdef :
  603. begin
  604. { string to char array }
  605. if (not is_special_array(def_to)) and
  606. (is_char(tarraydef(def_to).elementtype.def)or
  607. is_widechar(tarraydef(def_to).elementtype.def)) then
  608. begin
  609. doconv:=tc_string_2_chararray;
  610. eq:=te_convert_l1;
  611. end;
  612. end;
  613. orddef:
  614. begin
  615. if is_chararray(def_to) and
  616. is_char(def_from) then
  617. begin
  618. doconv:=tc_char_2_chararray;
  619. eq:=te_convert_l2;
  620. end;
  621. end;
  622. recorddef :
  623. begin
  624. { tvarrec -> array of const }
  625. if is_array_of_const(def_to) and
  626. equal_defs(def_from,tarraydef(def_to).elementtype.def) then
  627. begin
  628. doconv:=tc_equal;
  629. eq:=te_convert_l1;
  630. end;
  631. end;
  632. variantdef :
  633. begin
  634. if is_dynamic_array(def_to) then
  635. begin
  636. doconv:=tc_variant_2_dynarray;
  637. eq:=te_convert_l1;
  638. end;
  639. end;
  640. end;
  641. end;
  642. end;
  643. variantdef :
  644. begin
  645. if (cdo_allow_variant in cdoptions) then
  646. begin
  647. case def_from.deftype of
  648. enumdef :
  649. begin
  650. doconv:=tc_enum_2_variant;
  651. eq:=te_convert_l1;
  652. end;
  653. arraydef :
  654. begin
  655. if is_dynamic_array(def_from) then
  656. begin
  657. doconv:=tc_dynarray_2_variant;
  658. eq:=te_convert_l1;
  659. end;
  660. end;
  661. objectdef :
  662. begin
  663. if is_interface(def_from) then
  664. begin
  665. doconv:=tc_interface_2_variant;
  666. eq:=te_convert_l1;
  667. end;
  668. end;
  669. end;
  670. end;
  671. end;
  672. pointerdef :
  673. begin
  674. case def_from.deftype of
  675. stringdef :
  676. begin
  677. { string constant (which can be part of array constructor)
  678. to zero terminated string constant }
  679. if (fromtreetype in [arrayconstructorn,stringconstn]) and
  680. (is_pchar(def_to) or is_pwidechar(def_to)) then
  681. begin
  682. doconv:=tc_cstring_2_pchar;
  683. eq:=te_convert_l1;
  684. end
  685. else
  686. if cdo_explicit in cdoptions then
  687. begin
  688. { pchar(ansistring) }
  689. if is_pchar(def_to) and
  690. is_ansistring(def_from) then
  691. begin
  692. doconv:=tc_ansistring_2_pchar;
  693. eq:=te_convert_l1;
  694. end
  695. else
  696. { pwidechar(widestring) }
  697. if is_pwidechar(def_to) and
  698. is_widestring(def_from) then
  699. begin
  700. doconv:=tc_ansistring_2_pchar;
  701. eq:=te_convert_l1;
  702. end;
  703. end;
  704. end;
  705. orddef :
  706. begin
  707. { char constant to zero terminated string constant }
  708. if (fromtreetype=ordconstn) then
  709. begin
  710. if is_char(def_from) and
  711. is_pchar(def_to) then
  712. begin
  713. doconv:=tc_cchar_2_pchar;
  714. eq:=te_convert_l1;
  715. end
  716. else
  717. if (m_delphi in aktmodeswitches) and is_integer(def_from) then
  718. begin
  719. doconv:=tc_cord_2_pointer;
  720. eq:=te_convert_l1;
  721. end;
  722. end;
  723. { delphi compatible, allow explicit typecasts from
  724. ordinals to pointer.
  725. It is also used by the compiler internally for inc(pointer,ordinal) }
  726. if (eq=te_incompatible) and
  727. not is_void(def_from) and
  728. (
  729. (
  730. (m_delphi in aktmodeswitches) and
  731. (cdo_explicit in cdoptions)
  732. ) or
  733. (cdo_internal in cdoptions)
  734. ) then
  735. begin
  736. doconv:=tc_int_2_int;
  737. eq:=te_convert_l1;
  738. end;
  739. end;
  740. arraydef :
  741. begin
  742. { chararray to pointer }
  743. if is_zero_based_array(def_from) and
  744. equal_defs(tarraydef(def_from).elementtype.def,tpointerdef(def_to).pointertype.def) then
  745. begin
  746. doconv:=tc_array_2_pointer;
  747. eq:=te_convert_l1;
  748. end
  749. else
  750. { dynamic array to pointer, delphi only }
  751. if (m_delphi in aktmodeswitches) and
  752. is_dynamic_array(def_from) then
  753. begin
  754. eq:=te_equal;
  755. end;
  756. end;
  757. pointerdef :
  758. begin
  759. { check for far pointers }
  760. if (tpointerdef(def_from).is_far<>tpointerdef(def_to).is_far) then
  761. begin
  762. eq:=te_incompatible;
  763. end
  764. else
  765. { the types can be forward type, handle before normal type check !! }
  766. if assigned(def_to.typesym) and
  767. (tpointerdef(def_to).pointertype.def.deftype=forwarddef) then
  768. begin
  769. if (def_from.typesym=def_to.typesym) then
  770. eq:=te_equal
  771. end
  772. else
  773. { same types }
  774. if equal_defs(tpointerdef(def_from).pointertype.def,tpointerdef(def_to).pointertype.def) then
  775. begin
  776. eq:=te_equal
  777. end
  778. else
  779. { child class pointer can be assigned to anchestor pointers }
  780. if (
  781. (tpointerdef(def_from).pointertype.def.deftype=objectdef) and
  782. (tpointerdef(def_to).pointertype.def.deftype=objectdef) and
  783. tobjectdef(tpointerdef(def_from).pointertype.def).is_related(
  784. tobjectdef(tpointerdef(def_to).pointertype.def))
  785. ) then
  786. begin
  787. doconv:=tc_equal;
  788. eq:=te_convert_l1;
  789. end
  790. else
  791. { all pointers can be assigned to void-pointer }
  792. if is_void(tpointerdef(def_to).pointertype.def) then
  793. begin
  794. doconv:=tc_equal;
  795. { give pwidechar,pchar a penalty so it prefers
  796. conversion to ansistring }
  797. if is_pchar(def_from) or
  798. is_pwidechar(def_from) then
  799. eq:=te_convert_l2
  800. else
  801. eq:=te_convert_l1;
  802. end
  803. else
  804. { all pointers can be assigned from void-pointer }
  805. if is_void(tpointerdef(def_from).pointertype.def) then
  806. begin
  807. doconv:=tc_equal;
  808. { give pwidechar a penalty so it prefers
  809. conversion to pchar }
  810. if is_pwidechar(def_to) then
  811. eq:=te_convert_l2
  812. else
  813. eq:=te_convert_l1;
  814. end;
  815. end;
  816. procvardef :
  817. begin
  818. { procedure variable can be assigned to an void pointer,
  819. this not allowed for methodpointers }
  820. if is_void(tpointerdef(def_to).pointertype.def) and
  821. tprocvardef(def_from).is_addressonly then
  822. begin
  823. doconv:=tc_equal;
  824. eq:=te_convert_l1;
  825. end;
  826. end;
  827. classrefdef,
  828. objectdef :
  829. begin
  830. { class types and class reference type
  831. can be assigned to void pointers, but it is less
  832. preferred than assigning to a related objectdef }
  833. if (
  834. is_class_or_interface(def_from) or
  835. (def_from.deftype=classrefdef)
  836. ) and
  837. (tpointerdef(def_to).pointertype.def.deftype=orddef) and
  838. (torddef(tpointerdef(def_to).pointertype.def).typ=uvoid) then
  839. begin
  840. doconv:=tc_equal;
  841. eq:=te_convert_l2;
  842. end;
  843. end;
  844. end;
  845. end;
  846. setdef :
  847. begin
  848. case def_from.deftype of
  849. setdef :
  850. begin
  851. if assigned(tsetdef(def_from).elementtype.def) and
  852. assigned(tsetdef(def_to).elementtype.def) then
  853. begin
  854. { sets with the same element base type are equal }
  855. if is_subequal(tsetdef(def_from).elementtype.def,tsetdef(def_to).elementtype.def) then
  856. eq:=te_equal;
  857. end
  858. else
  859. { empty set is compatible with everything }
  860. eq:=te_equal;
  861. end;
  862. arraydef :
  863. begin
  864. { automatic arrayconstructor -> set conversion }
  865. if is_array_constructor(def_from) then
  866. begin
  867. doconv:=tc_arrayconstructor_2_set;
  868. eq:=te_convert_l1;
  869. end;
  870. end;
  871. end;
  872. end;
  873. procvardef :
  874. begin
  875. case def_from.deftype of
  876. procdef :
  877. begin
  878. { proc -> procvar }
  879. if (m_tp_procvar in aktmodeswitches) then
  880. begin
  881. subeq:=proc_to_procvar_equal(tprocdef(def_from),tprocvardef(def_to),true);
  882. if subeq>te_incompatible then
  883. begin
  884. doconv:=tc_proc_2_procvar;
  885. eq:=te_convert_l1;
  886. end;
  887. end;
  888. end;
  889. procvardef :
  890. begin
  891. { procvar -> procvar }
  892. eq:=proc_to_procvar_equal(tprocvardef(def_from),tprocvardef(def_to),false);
  893. end;
  894. pointerdef :
  895. begin
  896. { nil is compatible with procvars }
  897. if (fromtreetype=niln) then
  898. begin
  899. doconv:=tc_equal;
  900. eq:=te_convert_l1;
  901. end
  902. else
  903. { for example delphi allows the assignement from pointers }
  904. { to procedure variables }
  905. if (m_pointer_2_procedure in aktmodeswitches) and
  906. is_void(tpointerdef(def_from).pointertype.def) and
  907. tprocvardef(def_to).is_addressonly then
  908. begin
  909. doconv:=tc_equal;
  910. eq:=te_convert_l1;
  911. end;
  912. end;
  913. end;
  914. end;
  915. objectdef :
  916. begin
  917. { object pascal objects }
  918. if (def_from.deftype=objectdef) and
  919. (tobjectdef(def_from).is_related(tobjectdef(def_to))) then
  920. begin
  921. doconv:=tc_equal;
  922. eq:=te_convert_l1;
  923. end
  924. else
  925. { Class/interface specific }
  926. if is_class_or_interface(def_to) then
  927. begin
  928. { void pointer also for delphi mode }
  929. if (m_delphi in aktmodeswitches) and
  930. is_voidpointer(def_from) then
  931. begin
  932. doconv:=tc_equal;
  933. { prefer pointer-pointer assignments }
  934. eq:=te_convert_l2;
  935. end
  936. else
  937. { nil is compatible with class instances and interfaces }
  938. if (fromtreetype=niln) then
  939. begin
  940. doconv:=tc_equal;
  941. eq:=te_convert_l1;
  942. end
  943. { classes can be assigned to interfaces }
  944. else if is_interface(def_to) and
  945. is_class(def_from) and
  946. assigned(tobjectdef(def_from).implementedinterfaces) then
  947. begin
  948. { we've to search in parent classes as well }
  949. hd3:=tobjectdef(def_from);
  950. while assigned(hd3) do
  951. begin
  952. if hd3.implementedinterfaces.searchintf(def_to)<>-1 then
  953. begin
  954. doconv:=tc_class_2_intf;
  955. eq:=te_convert_l1;
  956. break;
  957. end;
  958. hd3:=hd3.childof;
  959. end;
  960. end
  961. { Interface 2 GUID handling }
  962. else if (def_to=tdef(rec_tguid)) and
  963. (fromtreetype=typen) and
  964. is_interface(def_from) and
  965. assigned(tobjectdef(def_from).iidguid) then
  966. begin
  967. eq:=te_convert_l1;
  968. doconv:=tc_equal;
  969. end
  970. else if (def_from.deftype=variantdef) and is_interface(def_to) then
  971. begin
  972. doconv:=tc_variant_2_interface;
  973. eq:=te_convert_l1;
  974. end
  975. { ugly, but delphi allows it }
  976. else if (eq=te_incompatible) and
  977. (def_from.deftype=orddef) and
  978. (m_delphi in aktmodeswitches) and
  979. (cdo_explicit in cdoptions) then
  980. begin
  981. doconv:=tc_int_2_int;
  982. eq:=te_convert_l1;
  983. end;
  984. end;
  985. end;
  986. classrefdef :
  987. begin
  988. { similar to pointerdef wrt forwards }
  989. if assigned(def_to.typesym) and
  990. (tclassrefdef(def_to).pointertype.def.deftype=forwarddef) then
  991. begin
  992. if (def_from.typesym=def_to.typesym) then
  993. eq:=te_equal;
  994. end
  995. else
  996. { class reference types }
  997. if (def_from.deftype=classrefdef) then
  998. begin
  999. if equal_defs(tclassrefdef(def_from).pointertype.def,tclassrefdef(def_to).pointertype.def) then
  1000. begin
  1001. eq:=te_equal;
  1002. end
  1003. else
  1004. begin
  1005. doconv:=tc_equal;
  1006. if (cdo_explicit in cdoptions) or
  1007. tobjectdef(tclassrefdef(def_from).pointertype.def).is_related(
  1008. tobjectdef(tclassrefdef(def_to).pointertype.def)) then
  1009. eq:=te_convert_l1;
  1010. end;
  1011. end
  1012. else
  1013. { nil is compatible with class references }
  1014. if (fromtreetype=niln) then
  1015. begin
  1016. doconv:=tc_equal;
  1017. eq:=te_convert_l1;
  1018. end;
  1019. end;
  1020. filedef :
  1021. begin
  1022. { typed files are all equal to the abstract file type
  1023. name TYPEDFILE in system.pp in is_equal in types.pas
  1024. the problem is that it sholud be also compatible to FILE
  1025. but this would leed to a problem for ASSIGN RESET and REWRITE
  1026. when trying to find the good overloaded function !!
  1027. so all file function are doubled in system.pp
  1028. this is not very beautiful !!}
  1029. if (def_from.deftype=filedef) then
  1030. begin
  1031. if (tfiledef(def_from).filetyp=tfiledef(def_to).filetyp) then
  1032. begin
  1033. if
  1034. (
  1035. (tfiledef(def_from).typedfiletype.def=nil) and
  1036. (tfiledef(def_to).typedfiletype.def=nil)
  1037. ) or
  1038. (
  1039. (tfiledef(def_from).typedfiletype.def<>nil) and
  1040. (tfiledef(def_to).typedfiletype.def<>nil) and
  1041. equal_defs(tfiledef(def_from).typedfiletype.def,tfiledef(def_to).typedfiletype.def)
  1042. ) or
  1043. (
  1044. (tfiledef(def_from).filetyp = ft_typed) and
  1045. (tfiledef(def_to).filetyp = ft_typed) and
  1046. (
  1047. (tfiledef(def_from).typedfiletype.def = tdef(voidtype.def)) or
  1048. (tfiledef(def_to).typedfiletype.def = tdef(voidtype.def))
  1049. )
  1050. ) then
  1051. begin
  1052. eq:=te_equal;
  1053. end;
  1054. end
  1055. else
  1056. if ((tfiledef(def_from).filetyp = ft_untyped) and
  1057. (tfiledef(def_to).filetyp = ft_typed)) or
  1058. ((tfiledef(def_from).filetyp = ft_typed) and
  1059. (tfiledef(def_to).filetyp = ft_untyped)) then
  1060. begin
  1061. doconv:=tc_equal;
  1062. eq:=te_convert_l1;
  1063. end;
  1064. end;
  1065. end;
  1066. recorddef :
  1067. begin
  1068. { interface -> guid }
  1069. if is_interface(def_from) and
  1070. (def_to=rec_tguid) then
  1071. begin
  1072. doconv:=tc_intf_2_guid;
  1073. eq:=te_convert_l1;
  1074. end;
  1075. end;
  1076. formaldef :
  1077. begin
  1078. doconv:=tc_equal;
  1079. if (def_from.deftype=formaldef) then
  1080. eq:=te_equal
  1081. else
  1082. { Just about everything can be converted to a formaldef...}
  1083. if not (def_from.deftype in [abstractdef,errordef]) then
  1084. eq:=te_convert_l1;
  1085. end;
  1086. end;
  1087. { if we didn't find an appropriate type conversion yet
  1088. then we search also the := operator }
  1089. if (eq=te_incompatible) and
  1090. (
  1091. { Check for variants? }
  1092. (
  1093. (cdo_allow_variant in cdoptions) and
  1094. ((def_from.deftype=variantdef) or (def_to.deftype=variantdef))
  1095. ) or
  1096. { Check for operators? }
  1097. (
  1098. (cdo_check_operator in cdoptions) and
  1099. ((def_from.deftype in [objectdef,recorddef,arraydef,stringdef,variantdef]) or
  1100. (def_to.deftype in [objectdef,recorddef,arraydef,stringdef,variantdef]))
  1101. )
  1102. ) then
  1103. begin
  1104. operatorpd:=search_assignment_operator(def_from,def_to);
  1105. if assigned(operatorpd) then
  1106. eq:=te_convert_operator;
  1107. end;
  1108. { update convtype for te_equal when it is not yet set }
  1109. if (eq=te_equal) and
  1110. (doconv=tc_not_possible) then
  1111. doconv:=tc_equal;
  1112. compare_defs_ext:=eq;
  1113. end;
  1114. function equal_defs(def_from,def_to:tdef):boolean;
  1115. var
  1116. convtyp : tconverttype;
  1117. pd : tprocdef;
  1118. begin
  1119. { Compare defs with nothingn and no explicit typecasts and
  1120. searching for overloaded operators is not needed }
  1121. equal_defs:=(compare_defs_ext(def_from,def_to,nothingn,convtyp,pd,[])>=te_equal);
  1122. end;
  1123. function compare_defs(def_from,def_to:tdef;fromtreetype:tnodetype):tequaltype;
  1124. var
  1125. doconv : tconverttype;
  1126. pd : tprocdef;
  1127. begin
  1128. compare_defs:=compare_defs_ext(def_from,def_to,fromtreetype,doconv,pd,[cdo_check_operator,cdo_allow_variant]);
  1129. end;
  1130. function is_subequal(def1, def2: tdef): boolean;
  1131. var
  1132. basedef1,basedef2 : tenumdef;
  1133. Begin
  1134. is_subequal := false;
  1135. if assigned(def1) and assigned(def2) then
  1136. Begin
  1137. if (def1.deftype = orddef) and (def2.deftype = orddef) then
  1138. Begin
  1139. { see p.47 of Turbo Pascal 7.01 manual for the separation of types }
  1140. { range checking for case statements is done with testrange }
  1141. case torddef(def1).typ of
  1142. u8bit,u16bit,u32bit,u64bit,
  1143. s8bit,s16bit,s32bit,s64bit :
  1144. is_subequal:=(torddef(def2).typ in [s64bit,u64bit,s32bit,u32bit,u8bit,s8bit,s16bit,u16bit]);
  1145. bool8bit,bool16bit,bool32bit :
  1146. is_subequal:=(torddef(def2).typ in [bool8bit,bool16bit,bool32bit]);
  1147. uchar :
  1148. is_subequal:=(torddef(def2).typ=uchar);
  1149. uwidechar :
  1150. is_subequal:=(torddef(def2).typ=uwidechar);
  1151. end;
  1152. end
  1153. else
  1154. Begin
  1155. { Check if both basedefs are equal }
  1156. if (def1.deftype=enumdef) and (def2.deftype=enumdef) then
  1157. Begin
  1158. { get both basedefs }
  1159. basedef1:=tenumdef(def1);
  1160. while assigned(basedef1.basedef) do
  1161. basedef1:=basedef1.basedef;
  1162. basedef2:=tenumdef(def2);
  1163. while assigned(basedef2.basedef) do
  1164. basedef2:=basedef2.basedef;
  1165. is_subequal:=(basedef1=basedef2);
  1166. end;
  1167. end;
  1168. end;
  1169. end;
  1170. function compare_paras(para1,para2 : tlist; acp : tcompare_paras_type; cpoptions: tcompare_paras_options):tequaltype;
  1171. var
  1172. currpara1,
  1173. currpara2 : tparavarsym;
  1174. eq,lowesteq : tequaltype;
  1175. hpd : tprocdef;
  1176. convtype : tconverttype;
  1177. cdoptions : tcompare_defs_options;
  1178. i1,i2 : byte;
  1179. begin
  1180. compare_paras:=te_incompatible;
  1181. cdoptions:=[cdo_check_operator,cdo_allow_variant];
  1182. { we need to parse the list from left-right so the
  1183. not-default parameters are checked first }
  1184. lowesteq:=high(tequaltype);
  1185. i1:=0;
  1186. i2:=0;
  1187. if cpo_ignorehidden in cpoptions then
  1188. begin
  1189. while (i1<para1.count) and
  1190. (vo_is_hidden_para in tparavarsym(para1[i1]).varoptions) do
  1191. inc(i1);
  1192. while (i2<para2.count) and
  1193. (vo_is_hidden_para in tparavarsym(para2[i2]).varoptions) do
  1194. inc(i2);
  1195. end;
  1196. while (i1<para1.count) and (i2<para2.count) do
  1197. begin
  1198. eq:=te_incompatible;
  1199. currpara1:=tparavarsym(para1[i1]);
  1200. currpara2:=tparavarsym(para2[i2]);
  1201. { Unique types must match exact }
  1202. if ((df_unique in currpara1.vartype.def.defoptions) or (df_unique in currpara2.vartype.def.defoptions)) and
  1203. (currpara1.vartype.def<>currpara2.vartype.def) then
  1204. exit;
  1205. { Handle hidden parameters separately, because self is
  1206. defined as voidpointer for methodpointers }
  1207. if (vo_is_hidden_para in currpara1.varoptions) or
  1208. (vo_is_hidden_para in currpara2.varoptions) then
  1209. begin
  1210. { both must be hidden }
  1211. if (vo_is_hidden_para in currpara1.varoptions)<>(vo_is_hidden_para in currpara2.varoptions) then
  1212. exit;
  1213. eq:=te_equal;
  1214. if not(vo_is_self in currpara1.varoptions) and
  1215. not(vo_is_self in currpara2.varoptions) then
  1216. begin
  1217. if (currpara1.varspez<>currpara2.varspez) then
  1218. exit;
  1219. eq:=compare_defs_ext(currpara1.vartype.def,currpara2.vartype.def,nothingn,
  1220. convtype,hpd,cdoptions);
  1221. end;
  1222. end
  1223. else
  1224. begin
  1225. case acp of
  1226. cp_value_equal_const :
  1227. begin
  1228. if (
  1229. (currpara1.varspez<>currpara2.varspez) and
  1230. ((currpara1.varspez in [vs_var,vs_out]) or
  1231. (currpara2.varspez in [vs_var,vs_out]))
  1232. ) then
  1233. exit;
  1234. eq:=compare_defs_ext(currpara1.vartype.def,currpara2.vartype.def,nothingn,
  1235. convtype,hpd,cdoptions);
  1236. end;
  1237. cp_all :
  1238. begin
  1239. if (currpara1.varspez<>currpara2.varspez) then
  1240. exit;
  1241. eq:=compare_defs_ext(currpara1.vartype.def,currpara2.vartype.def,nothingn,
  1242. convtype,hpd,cdoptions);
  1243. end;
  1244. cp_procvar :
  1245. begin
  1246. if (currpara1.varspez<>currpara2.varspez) then
  1247. exit;
  1248. eq:=compare_defs_ext(currpara1.vartype.def,currpara2.vartype.def,nothingn,
  1249. convtype,hpd,cdoptions);
  1250. { Parameters must be at least equal otherwise the are incompatible }
  1251. if (eq<te_equal) then
  1252. eq:=te_incompatible;
  1253. end;
  1254. else
  1255. eq:=compare_defs_ext(currpara1.vartype.def,currpara2.vartype.def,nothingn,
  1256. convtype,hpd,cdoptions);
  1257. end;
  1258. end;
  1259. { check type }
  1260. if eq=te_incompatible then
  1261. exit;
  1262. if eq<lowesteq then
  1263. lowesteq:=eq;
  1264. { also check default value if both have it declared }
  1265. if (cpo_comparedefaultvalue in cpoptions) and
  1266. assigned(currpara1.defaultconstsym) and
  1267. assigned(currpara2.defaultconstsym) then
  1268. begin
  1269. if not equal_constsym(tconstsym(currpara1.defaultconstsym),tconstsym(currpara2.defaultconstsym)) then
  1270. exit;
  1271. end;
  1272. inc(i1);
  1273. inc(i2);
  1274. if cpo_ignorehidden in cpoptions then
  1275. begin
  1276. while (i1<para1.count) and
  1277. (vo_is_hidden_para in tparavarsym(para1[i1]).varoptions) do
  1278. inc(i1);
  1279. while (i2<para2.count) and
  1280. (vo_is_hidden_para in tparavarsym(para2[i2]).varoptions) do
  1281. inc(i2);
  1282. end;
  1283. end;
  1284. { when both lists are empty then the parameters are equal. Also
  1285. when one list is empty and the other has a parameter with default
  1286. value assigned then the parameters are also equal }
  1287. if ((i1>=para1.count) and (i2>=para2.count)) or
  1288. ((cpo_allowdefaults in cpoptions) and
  1289. (((i1<para1.count) and assigned(tparavarsym(para1[i1]).defaultconstsym)) or
  1290. ((i2<para2.count) and assigned(tparavarsym(para2[i2]).defaultconstsym)))) then
  1291. compare_paras:=lowesteq;
  1292. end;
  1293. function proc_to_procvar_equal(def1:tabstractprocdef;def2:tprocvardef;methoderr:boolean):tequaltype;
  1294. var
  1295. eq : tequaltype;
  1296. po_comp : tprocoptions;
  1297. begin
  1298. proc_to_procvar_equal:=te_incompatible;
  1299. if not(assigned(def1)) or not(assigned(def2)) then
  1300. exit;
  1301. { check for method pointer }
  1302. if (def1.is_methodpointer xor def2.is_methodpointer) or
  1303. (def1.is_addressonly xor def2.is_addressonly) then
  1304. begin
  1305. if methoderr then
  1306. Message(type_e_no_method_and_procedure_not_compatible);
  1307. exit;
  1308. end;
  1309. { check return value and options, methodpointer is already checked }
  1310. po_comp:=[po_staticmethod,po_interrupt,
  1311. po_iocheck,po_varargs];
  1312. if (m_delphi in aktmodeswitches) then
  1313. exclude(po_comp,po_varargs);
  1314. if (def1.proccalloption=def2.proccalloption) and
  1315. ((po_comp * def1.procoptions)= (po_comp * def2.procoptions)) and
  1316. equal_defs(def1.rettype.def,def2.rettype.def) then
  1317. begin
  1318. { return equal type based on the parameters, but a proc->procvar
  1319. is never exact, so map an exact match of the parameters to
  1320. te_equal }
  1321. eq:=compare_paras(def1.paras,def2.paras,cp_procvar,[]);
  1322. if eq=te_exact then
  1323. eq:=te_equal;
  1324. proc_to_procvar_equal:=eq;
  1325. end;
  1326. end;
  1327. end.
  1328. {
  1329. $Log$
  1330. Revision 1.68 2005-02-03 19:24:33 florian
  1331. + support for another explicit ugly delphi type cast added
  1332. Revision 1.67 2005/02/02 19:04:31 florian
  1333. * <class/interface>(<any ord. type>) in delphi mode allowed
  1334. Revision 1.66 2005/01/10 22:10:26 peter
  1335. * widestring patches from Alexey Barkovoy
  1336. Revision 1.65 2005/01/07 21:14:21 florian
  1337. + compiler side of variant<->interface implemented
  1338. Revision 1.64 2005/01/06 13:30:40 florian
  1339. * widechararray patch from Peter
  1340. Revision 1.63 2005/01/03 17:55:57 florian
  1341. + first batch of patches to support tdef.getcopy fully
  1342. Revision 1.62 2004/12/05 12:28:10 peter
  1343. * procvar handling for tp procvar mode fixed
  1344. * proc to procvar moved from addrnode to typeconvnode
  1345. * inlininginfo is now allocated only for inline routines that
  1346. can be inlined, introduced a new flag po_has_inlining_info
  1347. Revision 1.61 2004/11/29 17:32:56 peter
  1348. * prevent some IEs with delphi methodpointers
  1349. Revision 1.60 2004/11/26 22:33:54 peter
  1350. * don't allow pointer(ordinal) typecast in fpc mode, only allow it
  1351. for delphi and for internal use
  1352. Revision 1.59 2004/11/15 23:35:31 peter
  1353. * tparaitem removed, use tparavarsym instead
  1354. * parameter order is now calculated from paranr value in tparavarsym
  1355. Revision 1.58 2004/11/08 22:09:58 peter
  1356. * tvarsym splitted
  1357. Revision 1.57 2004/11/01 10:31:48 peter
  1358. * procvar arguments need to be at least equal
  1359. Revision 1.56 2004/11/01 08:02:26 peter
  1360. * remove previous patch
  1361. Revision 1.55 2004/10/31 22:05:25 peter
  1362. * only allow ordinal-pointer for same size
  1363. Revision 1.54 2004/10/31 21:45:02 peter
  1364. * generic tlocation
  1365. * move tlocation to cgutils
  1366. Revision 1.53 2004/09/21 15:52:35 peter
  1367. * prefer pchar-string over pchar-pointer
  1368. Revision 1.52 2004/09/16 16:32:44 peter
  1369. * dynarr-pointer is allowed under delphi
  1370. Revision 1.51 2004/06/20 08:55:29 florian
  1371. * logs truncated
  1372. Revision 1.50 2004/04/12 11:26:10 peter
  1373. * voidpointer can be converted to dynarray
  1374. Revision 1.49 2004/03/04 17:22:32 peter
  1375. * use defs_equal when comparing pointer types
  1376. Revision 1.48 2004/03/03 22:02:16 peter
  1377. * also compare calling convention in proc_to_procvar_equal
  1378. Revision 1.47 2004/02/24 16:12:39 peter
  1379. * operator overload chooses rewrite
  1380. * overload choosing is now generic and moved to htypechk
  1381. Revision 1.46 2004/02/15 12:18:22 peter
  1382. * allow real_2_real conversion for realconstn, fixes 2971
  1383. }