defcmp.pas 107 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421
  1. {
  2. Copyright (c) 1998-2002 by Florian Klaempfl
  3. Compare definitions and parameter lists
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit defcmp;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. cclasses,
  22. globtype,globals,
  23. node,
  24. symconst,symtype,symdef;
  25. type
  26. { if acp is cp_all the var const or nothing are considered equal }
  27. tcompare_paras_type = ( cp_none, cp_value_equal_const, cp_all,cp_procvar);
  28. tcompare_paras_option = (
  29. cpo_allowdefaults,
  30. cpo_ignorehidden, // ignore hidden parameters
  31. cpo_allowconvert,
  32. cpo_comparedefaultvalue,
  33. cpo_openequalisexact,
  34. cpo_ignoreuniv,
  35. cpo_warn_incompatible_univ,
  36. cpo_ignorevarspez, // ignore parameter access type
  37. cpo_ignoreframepointer, // ignore frame pointer parameter (for assignment-compatibility of global procedures to nested procvars)
  38. cpo_compilerproc,
  39. cpo_rtlproc
  40. );
  41. tcompare_paras_options = set of tcompare_paras_option;
  42. tcompare_defs_option = (
  43. cdo_internal,
  44. cdo_explicit,
  45. cdo_check_operator,
  46. cdo_allow_variant,
  47. cdo_parameter,
  48. cdo_warn_incompatible_univ,
  49. cdo_strict_undefined_check // undefined defs are incompatible to everything except other undefined defs
  50. );
  51. tcompare_defs_options = set of tcompare_defs_option;
  52. tconverttype = (tc_none,
  53. tc_equal,
  54. tc_not_possible,
  55. tc_string_2_string,
  56. tc_char_2_string,
  57. tc_char_2_chararray,
  58. tc_pchar_2_string,
  59. tc_cchar_2_pchar,
  60. tc_cstring_2_pchar,
  61. tc_cstring_2_int,
  62. tc_ansistring_2_pchar,
  63. tc_string_2_chararray,
  64. tc_chararray_2_string,
  65. tc_array_2_pointer,
  66. tc_pointer_2_array,
  67. tc_int_2_int,
  68. tc_int_2_bool,
  69. tc_bool_2_bool,
  70. tc_bool_2_int,
  71. tc_real_2_real,
  72. tc_int_2_real,
  73. tc_real_2_currency,
  74. tc_proc_2_procvar,
  75. tc_nil_2_methodprocvar,
  76. tc_arrayconstructor_2_set,
  77. tc_set_to_set,
  78. tc_cord_2_pointer,
  79. tc_intf_2_string,
  80. tc_intf_2_guid,
  81. tc_class_2_intf,
  82. tc_char_2_char,
  83. tc_dynarray_2_openarray,
  84. tc_pwchar_2_string,
  85. tc_variant_2_dynarray,
  86. tc_dynarray_2_variant,
  87. tc_variant_2_enum,
  88. tc_enum_2_variant,
  89. tc_interface_2_variant,
  90. tc_variant_2_interface,
  91. tc_array_2_dynarray,
  92. tc_elem_2_openarray
  93. );
  94. function compare_defs_ext(def_from,def_to : tdef;
  95. fromtreetype : tnodetype;
  96. var doconv : tconverttype;
  97. var operatorpd : tprocdef;
  98. cdoptions:tcompare_defs_options):tequaltype;
  99. { Returns if the type def_from can be converted to def_to or if both types are equal }
  100. function compare_defs(def_from,def_to:tdef;fromtreetype:tnodetype):tequaltype;
  101. { Returns true, if def1 and def2 are semantically the same }
  102. function equal_defs(def_from,def_to:tdef):boolean;
  103. { Checks for type compatibility (subgroups of type)
  104. used for case statements... probably missing stuff
  105. to use on other types }
  106. function is_subequal(def1, def2: tdef): boolean;
  107. {# true, if two parameter lists are equal
  108. if acp is cp_all, all have to match exactly
  109. if acp is cp_value_equal_const call by value
  110. and call by const parameter are assumed as
  111. equal
  112. if acp is cp_procvar then the varspez have to match,
  113. and all parameter types must be at least te_equal
  114. if acp is cp_none, then we don't check the varspez at all
  115. allowdefaults indicates if default value parameters
  116. are allowed (in this case, the search order will first
  117. search for a routine with default parameters, before
  118. searching for the same definition with no parameters)
  119. para1 is expected to be parameter list of the first encountered
  120. declaration (interface, forward), and para2 that of the second one
  121. (important in case of cpo_comparedefaultvalue)
  122. }
  123. function compare_paras(para1,para2 : TFPObjectList; acp : tcompare_paras_type; cpoptions: tcompare_paras_options):tequaltype;
  124. { True if a function can be assigned to a procvar }
  125. { changed first argument type to pabstractprocdef so that it can also be }
  126. { used to test compatibility between two pprocvardefs (JM) }
  127. function proc_to_procvar_equal(def1:tabstractprocdef;def2:tprocvardef;checkincompatibleuniv: boolean):tequaltype;
  128. { Parentdef is the definition of a method defined in a parent class or interface }
  129. { Childdef is the definition of a method defined in a child class, interface or }
  130. { a class implementing an interface with parentdef. }
  131. { Returns true if the resultdef of childdef can be used to implement/override }
  132. { parentdef's resultdef }
  133. function compatible_childmethod_resultdef(parentretdef, childretdef: tdef): boolean;
  134. { Checks whether the class impldef or one of its parent classes implements }
  135. { the interface intfdef and returns the corresponding "implementation link }
  136. function find_implemented_interface(impldef,intfdef:tobjectdef):timplementedinterface;
  137. { Checks whether to defs are related to each other. Thereby the following }
  138. { cases of curdef are implemented: }
  139. { - stringdef: on JVM JLObject, JLString and AnsiString are compatible }
  140. { - recorddef: on JVM records are compatible to java_fpcbaserecordtype }
  141. { and JLObject }
  142. { - objectdef: if it inherits from otherdef or they are equal }
  143. function def_is_related(curdef,otherdef:tdef):boolean;
  144. implementation
  145. uses
  146. verbose,systems,constexp,
  147. symtable,symsym,symcpu,
  148. defutil,symutil;
  149. function compare_defs_ext(def_from,def_to : tdef;
  150. fromtreetype : tnodetype;
  151. var doconv : tconverttype;
  152. var operatorpd : tprocdef;
  153. cdoptions:tcompare_defs_options):tequaltype;
  154. { tordtype:
  155. uvoid,
  156. u8bit,u16bit,u32bit,u64bit,
  157. s8bit,s16bit,s32bit,s64bit,
  158. pasbool, bool8bit,bool16bit,bool32bit,bool64bit,
  159. uchar,uwidechar,scurrency }
  160. type
  161. tbasedef=(bvoid,bchar,bint,bbool);
  162. const
  163. basedeftbl:array[tordtype] of tbasedef =
  164. (bvoid,
  165. bint,bint,bint,bint,
  166. bint,bint,bint,bint,
  167. bbool,bbool,bbool,bbool,
  168. bbool,bbool,bbool,bbool,
  169. bchar,bchar,bint);
  170. basedefconvertsimplicit : array[tbasedef,tbasedef] of tconverttype =
  171. { void, char, int, bool }
  172. ((tc_not_possible,tc_not_possible,tc_not_possible,tc_not_possible),
  173. (tc_not_possible,tc_char_2_char,tc_not_possible,tc_not_possible),
  174. (tc_not_possible,tc_not_possible,tc_int_2_int,tc_not_possible),
  175. (tc_not_possible,tc_not_possible,tc_not_possible,tc_bool_2_bool));
  176. basedefconvertsexplicit : array[tbasedef,tbasedef] of tconverttype =
  177. { void, char, int, bool }
  178. ((tc_not_possible,tc_not_possible,tc_not_possible,tc_not_possible),
  179. (tc_not_possible,tc_char_2_char,tc_int_2_int,tc_int_2_bool),
  180. (tc_not_possible,tc_int_2_int,tc_int_2_int,tc_int_2_bool),
  181. (tc_not_possible,tc_bool_2_int,tc_bool_2_int,tc_bool_2_bool));
  182. var
  183. subeq,eq : tequaltype;
  184. hd1,hd2 : tdef;
  185. def_generic : tstoreddef;
  186. hct : tconverttype;
  187. hobjdef : tobjectdef;
  188. hpd : tprocdef;
  189. i : longint;
  190. diff : boolean;
  191. symfrom,symto : tsym;
  192. begin
  193. eq:=te_incompatible;
  194. doconv:=tc_not_possible;
  195. { safety check }
  196. if not(assigned(def_from) and assigned(def_to)) then
  197. begin
  198. compare_defs_ext:=te_incompatible;
  199. exit;
  200. end;
  201. { resolve anonymous external definitions }
  202. if def_from.typ=objectdef then
  203. def_from:=find_real_class_definition(tobjectdef(def_from),false);
  204. if def_to.typ=objectdef then
  205. def_to:=find_real_class_definition(tobjectdef(def_to),false);
  206. { same def? then we've an exact match }
  207. if def_from=def_to then
  208. begin
  209. doconv:=tc_equal;
  210. compare_defs_ext:=te_exact;
  211. exit;
  212. end;
  213. if cdo_strict_undefined_check in cdoptions then
  214. begin
  215. { undefined defs are considered equal if both are undefined defs }
  216. if (def_from.typ=undefineddef) and
  217. (def_to.typ=undefineddef) then
  218. begin
  219. doconv:=tc_equal;
  220. compare_defs_ext:=te_exact;
  221. exit;
  222. end;
  223. { if only one def is a undefined def then they are not considered as
  224. equal}
  225. if (
  226. (def_from.typ=undefineddef) or
  227. assigned(tstoreddef(def_from).genconstraintdata)
  228. ) or (
  229. (def_to.typ=undefineddef) or
  230. assigned(tstoreddef(def_to).genconstraintdata)
  231. ) then
  232. begin
  233. doconv:=tc_not_possible;
  234. compare_defs_ext:=te_incompatible;
  235. exit;
  236. end;
  237. end
  238. else
  239. begin
  240. { undefined defs or defs with generic constraints are
  241. considered equal to everything }
  242. if (
  243. (def_from.typ=undefineddef) or
  244. assigned(tstoreddef(def_from).genconstraintdata)
  245. ) or (
  246. (def_to.typ=undefineddef) or
  247. assigned(tstoreddef(def_to).genconstraintdata)
  248. ) then
  249. begin
  250. doconv:=tc_equal;
  251. compare_defs_ext:=te_exact;
  252. exit;
  253. end;
  254. end;
  255. { two specializations are considered equal if they specialize the same
  256. generic with the same types }
  257. if (df_specialization in def_from.defoptions) and
  258. (df_specialization in def_to.defoptions) and
  259. (tstoreddef(def_from).genericdef=tstoreddef(def_to).genericdef) then
  260. begin
  261. if assigned(tstoreddef(def_from).genericparas) xor
  262. assigned(tstoreddef(def_to).genericparas) then
  263. internalerror(2013030901);
  264. diff:=false;
  265. if assigned(tstoreddef(def_from).genericparas) then
  266. begin
  267. if tstoreddef(def_from).genericparas.count<>tstoreddef(def_to).genericparas.count then
  268. internalerror(2012091301);
  269. for i:=0 to tstoreddef(def_from).genericparas.count-1 do
  270. begin
  271. if tstoreddef(def_from).genericparas.nameofindex(i)<>tstoreddef(def_to).genericparas.nameofindex(i) then
  272. internalerror(2012091302);
  273. symfrom:=ttypesym(tstoreddef(def_from).genericparas[i]);
  274. symto:=ttypesym(tstoreddef(def_to).genericparas[i]);
  275. if not (symfrom.typ=typesym) or not (symto.typ=typesym) then
  276. internalerror(2012121401);
  277. if not equal_defs(ttypesym(symfrom).typedef,ttypesym(symto).typedef) then
  278. diff:=true;
  279. if diff then
  280. break;
  281. end;
  282. end;
  283. if not diff then
  284. begin
  285. doconv:=tc_equal;
  286. { the definitions are not exactly the same, but only equal }
  287. compare_defs_ext:=te_equal;
  288. exit;
  289. end;
  290. end;
  291. { handling of partial specializations }
  292. if (
  293. (df_generic in def_to.defoptions) and
  294. (df_specialization in def_from.defoptions) and
  295. (tstoreddef(def_from).genericdef=def_to)
  296. ) or (
  297. (df_generic in def_from.defoptions) and
  298. (df_specialization in def_to.defoptions) and
  299. (tstoreddef(def_to).genericdef=def_from)
  300. ) then
  301. begin
  302. if tstoreddef(def_from).genericdef=def_to then
  303. def_generic:=tstoreddef(def_to)
  304. else
  305. def_generic:=tstoreddef(def_from);
  306. if not assigned(def_generic.genericparas) then
  307. internalerror(2014052306);
  308. diff:=false;
  309. for i:=0 to def_generic.genericparas.count-1 do
  310. begin
  311. symfrom:=tsym(def_generic.genericparas[i]);
  312. if symfrom.typ<>typesym then
  313. internalerror(2014052307);
  314. if ttypesym(symfrom).typedef.typ<>undefineddef then
  315. diff:=true;
  316. if diff then
  317. break;
  318. end;
  319. if not diff then
  320. begin
  321. doconv:=tc_equal;
  322. { the definitions are not exactly the same, but only equal }
  323. compare_defs_ext:=te_equal;
  324. exit;
  325. end;
  326. end;
  327. { we walk the wanted (def_to) types and check then the def_from
  328. types if there is a conversion possible }
  329. case def_to.typ of
  330. orddef :
  331. begin
  332. case def_from.typ of
  333. orddef :
  334. begin
  335. if (torddef(def_from).ordtype=torddef(def_to).ordtype) then
  336. begin
  337. case torddef(def_from).ordtype of
  338. uchar,uwidechar,
  339. u8bit,u16bit,u32bit,u64bit,
  340. s8bit,s16bit,s32bit,s64bit:
  341. begin
  342. if (torddef(def_from).low>=torddef(def_to).low) and
  343. (torddef(def_from).high<=torddef(def_to).high) then
  344. eq:=te_equal
  345. else
  346. begin
  347. doconv:=tc_int_2_int;
  348. eq:=te_convert_l1;
  349. end;
  350. end;
  351. uvoid,
  352. pasbool8,pasbool16,pasbool32,pasbool64,
  353. bool8bit,bool16bit,bool32bit,bool64bit:
  354. eq:=te_equal;
  355. else
  356. internalerror(200210061);
  357. end;
  358. end
  359. { currency cannot be implicitly converted to an ordinal
  360. type }
  361. else if not is_currency(def_from) or
  362. (cdo_explicit in cdoptions) then
  363. begin
  364. if cdo_explicit in cdoptions then
  365. doconv:=basedefconvertsexplicit[basedeftbl[torddef(def_from).ordtype],basedeftbl[torddef(def_to).ordtype]]
  366. else
  367. doconv:=basedefconvertsimplicit[basedeftbl[torddef(def_from).ordtype],basedeftbl[torddef(def_to).ordtype]];
  368. if (doconv=tc_not_possible) then
  369. eq:=te_incompatible
  370. else if (not is_in_limit(def_from,def_to)) then
  371. { "punish" bad type conversions :) (JM) }
  372. eq:=te_convert_l3
  373. else
  374. eq:=te_convert_l1;
  375. end;
  376. end;
  377. enumdef :
  378. begin
  379. { needed for char(enum) }
  380. if cdo_explicit in cdoptions then
  381. begin
  382. doconv:=tc_int_2_int;
  383. eq:=te_convert_l1;
  384. end;
  385. end;
  386. floatdef :
  387. begin
  388. if is_currency(def_to) then
  389. begin
  390. doconv:=tc_real_2_currency;
  391. eq:=te_convert_l2;
  392. end;
  393. end;
  394. objectdef:
  395. begin
  396. if (m_delphi in current_settings.modeswitches) and
  397. is_implicit_pointer_object_type(def_from) and
  398. (cdo_explicit in cdoptions) then
  399. begin
  400. eq:=te_convert_l1;
  401. if (fromtreetype=niln) then
  402. begin
  403. { will be handled by the constant folding }
  404. doconv:=tc_equal;
  405. end
  406. else
  407. doconv:=tc_int_2_int;
  408. end;
  409. end;
  410. classrefdef,
  411. procvardef,
  412. pointerdef :
  413. begin
  414. if cdo_explicit in cdoptions then
  415. begin
  416. eq:=te_convert_l1;
  417. if (fromtreetype=niln) then
  418. begin
  419. { will be handled by the constant folding }
  420. doconv:=tc_equal;
  421. end
  422. else
  423. doconv:=tc_int_2_int;
  424. end;
  425. end;
  426. arraydef :
  427. begin
  428. if (m_mac in current_settings.modeswitches) and
  429. (fromtreetype=stringconstn) then
  430. begin
  431. eq:=te_convert_l3;
  432. doconv:=tc_cstring_2_int;
  433. end;
  434. end;
  435. end;
  436. end;
  437. stringdef :
  438. begin
  439. case def_from.typ of
  440. stringdef :
  441. begin
  442. { Constant string }
  443. if (fromtreetype=stringconstn) and
  444. is_shortstring(def_from) and
  445. is_shortstring(def_to) then
  446. eq:=te_equal
  447. else if (tstringdef(def_to).stringtype=st_ansistring) and
  448. (tstringdef(def_from).stringtype=st_ansistring) then
  449. begin
  450. { don't convert ansistrings if any condition is true:
  451. 1) same encoding
  452. 2) from explicit codepage ansistring to ansistring and vice versa
  453. 3) from any ansistring to rawbytestring
  454. 4) from rawbytestring to any ansistring }
  455. if (tstringdef(def_from).encoding=tstringdef(def_to).encoding) or
  456. ((tstringdef(def_to).encoding=0) and (tstringdef(def_from).encoding=getansistringcodepage)) or
  457. ((tstringdef(def_to).encoding=getansistringcodepage) and (tstringdef(def_from).encoding=0)) or
  458. (tstringdef(def_to).encoding=globals.CP_NONE) or
  459. (tstringdef(def_from).encoding=globals.CP_NONE) then
  460. begin
  461. eq:=te_equal;
  462. end
  463. else
  464. begin
  465. doconv := tc_string_2_string;
  466. { prefere conversion to utf8 codepage }
  467. if tstringdef(def_to).encoding = globals.CP_UTF8 then
  468. eq:=te_convert_l1
  469. { else to AnsiString type }
  470. else if def_to=getansistringdef then
  471. eq:=te_convert_l2
  472. { else to AnsiString with other codepage }
  473. else
  474. eq:=te_convert_l3;
  475. end
  476. end
  477. else
  478. { same string type ? }
  479. if (tstringdef(def_from).stringtype=tstringdef(def_to).stringtype) and
  480. { for shortstrings also the length must match }
  481. ((tstringdef(def_from).stringtype<>st_shortstring) or
  482. (tstringdef(def_from).len=tstringdef(def_to).len)) and
  483. { for ansi- and unicodestrings also the encoding must match }
  484. (not(tstringdef(def_from).stringtype in [st_ansistring,st_unicodestring]) or
  485. (tstringdef(def_from).encoding=tstringdef(def_to).encoding)) then
  486. eq:=te_equal
  487. else
  488. begin
  489. doconv:=tc_string_2_string;
  490. case tstringdef(def_from).stringtype of
  491. st_widestring :
  492. begin
  493. case tstringdef(def_to).stringtype of
  494. { Prefer conversions to unicodestring }
  495. st_unicodestring: eq:=te_convert_l1;
  496. { else prefer conversions to ansistring }
  497. st_ansistring: eq:=te_convert_l2;
  498. else
  499. eq:=te_convert_l3;
  500. end;
  501. end;
  502. st_unicodestring :
  503. begin
  504. case tstringdef(def_to).stringtype of
  505. { Prefer conversions to widestring }
  506. st_widestring: eq:=te_convert_l1;
  507. { else prefer conversions to ansistring }
  508. st_ansistring: eq:=te_convert_l2;
  509. else
  510. eq:=te_convert_l3;
  511. end;
  512. end;
  513. st_shortstring :
  514. begin
  515. { Prefer shortstrings of different length or conversions
  516. from shortstring to ansistring }
  517. case tstringdef(def_to).stringtype of
  518. st_shortstring: eq:=te_convert_l1;
  519. st_ansistring:
  520. if tstringdef(def_to).encoding=globals.CP_UTF8 then
  521. eq:=te_convert_l2
  522. else if def_to=getansistringdef then
  523. eq:=te_convert_l3
  524. else
  525. eq:=te_convert_l4;
  526. st_unicodestring: eq:=te_convert_l5;
  527. else
  528. eq:=te_convert_l6;
  529. end;
  530. end;
  531. st_ansistring :
  532. begin
  533. { Prefer conversion to widestrings }
  534. case tstringdef(def_to).stringtype of
  535. st_unicodestring: eq:=te_convert_l4;
  536. st_widestring: eq:=te_convert_l5;
  537. else
  538. eq:=te_convert_l6;
  539. end;
  540. end;
  541. end;
  542. end;
  543. end;
  544. orddef :
  545. begin
  546. { char to string}
  547. if is_char(def_from) then
  548. begin
  549. doconv:=tc_char_2_string;
  550. case tstringdef(def_to).stringtype of
  551. st_shortstring: eq:=te_convert_l1;
  552. st_ansistring: eq:=te_convert_l2;
  553. st_unicodestring: eq:=te_convert_l3;
  554. st_widestring: eq:=te_convert_l4;
  555. else
  556. eq:=te_convert_l5;
  557. end;
  558. end
  559. else
  560. if is_widechar(def_from) then
  561. begin
  562. doconv:=tc_char_2_string;
  563. case tstringdef(def_to).stringtype of
  564. st_unicodestring: eq:=te_convert_l1;
  565. st_widestring: eq:=te_convert_l2;
  566. st_ansistring: eq:=te_convert_l3;
  567. st_shortstring: eq:=te_convert_l4;
  568. else
  569. eq:=te_convert_l5;
  570. end;
  571. end;
  572. end;
  573. arraydef :
  574. begin
  575. { array of char to string, the length check is done by the firstpass of this node }
  576. if (is_chararray(def_from) or
  577. is_open_chararray(def_from)) and
  578. { bitpacked arrays of char whose element bitsize is not
  579. 8 cannot be auto-converted to strings }
  580. (not is_packed_array(def_from) or
  581. (tarraydef(def_from).elementdef.packedbitsize=8)) then
  582. begin
  583. { "Untyped" stringconstn is an array of char }
  584. if fromtreetype=stringconstn then
  585. begin
  586. doconv:=tc_string_2_string;
  587. { prefered string type depends on the $H switch }
  588. if (m_default_unicodestring in current_settings.modeswitches) and
  589. (cs_refcountedstrings in current_settings.localswitches) then
  590. case tstringdef(def_to).stringtype of
  591. st_unicodestring: eq:=te_equal;
  592. st_widestring: eq:=te_convert_l1;
  593. // widechar: eq:=te_convert_l2;
  594. // ansichar: eq:=te_convert_l3;
  595. st_ansistring: eq:=te_convert_l4;
  596. st_shortstring: eq:=te_convert_l5;
  597. else
  598. eq:=te_convert_l6;
  599. end
  600. else if not(cs_refcountedstrings in current_settings.localswitches) and
  601. (tstringdef(def_to).stringtype=st_shortstring) then
  602. eq:=te_equal
  603. else if not(m_default_unicodestring in current_settings.modeswitches) and
  604. (cs_refcountedstrings in current_settings.localswitches) and
  605. (tstringdef(def_to).stringtype=st_ansistring) then
  606. eq:=te_equal
  607. else if tstringdef(def_to).stringtype in [st_widestring,st_unicodestring] then
  608. eq:=te_convert_l3
  609. else
  610. eq:=te_convert_l1;
  611. end
  612. else
  613. begin
  614. doconv:=tc_chararray_2_string;
  615. if is_open_array(def_from) then
  616. begin
  617. if is_ansistring(def_to) then
  618. eq:=te_convert_l1
  619. else if is_wide_or_unicode_string(def_to) then
  620. eq:=te_convert_l3
  621. else
  622. eq:=te_convert_l2;
  623. end
  624. else
  625. begin
  626. if is_shortstring(def_to) then
  627. begin
  628. { Only compatible with arrays that fit
  629. smaller than 255 chars }
  630. if (def_from.size <= 255) then
  631. eq:=te_convert_l1;
  632. end
  633. else if is_ansistring(def_to) then
  634. begin
  635. if (def_from.size > 255) then
  636. eq:=te_convert_l1
  637. else
  638. eq:=te_convert_l2;
  639. end
  640. else if is_wide_or_unicode_string(def_to) then
  641. eq:=te_convert_l3
  642. else
  643. eq:=te_convert_l2;
  644. end;
  645. end;
  646. end
  647. else
  648. { array of widechar to string, the length check is done by the firstpass of this node }
  649. if is_widechararray(def_from) or is_open_widechararray(def_from) then
  650. begin
  651. doconv:=tc_chararray_2_string;
  652. if is_wide_or_unicode_string(def_to) then
  653. eq:=te_convert_l1
  654. else
  655. { size of widechar array is double due the sizeof a widechar }
  656. if not(is_shortstring(def_to) and (is_open_widechararray(def_from) or (def_from.size>255*sizeof(widechar)))) then
  657. eq:=te_convert_l3
  658. else
  659. eq:=te_convert_l2;
  660. end;
  661. end;
  662. pointerdef :
  663. begin
  664. { pchar can be assigned to short/ansistrings,
  665. but not in tp7 compatible mode }
  666. if not(m_tp7 in current_settings.modeswitches) then
  667. begin
  668. if is_pchar(def_from) then
  669. begin
  670. doconv:=tc_pchar_2_string;
  671. { prefer ansistrings/unicodestrings because pchars
  672. can overflow shortstrings; don't use l1/l2/l3
  673. because then pchar -> ansistring has the same
  674. preference as conststring -> pchar, and this
  675. breaks webtbs/tw3328.pp }
  676. if is_ansistring(def_to) then
  677. eq:=te_convert_l2
  678. else if is_wide_or_unicode_string(def_to) then
  679. eq:=te_convert_l3
  680. else
  681. eq:=te_convert_l4
  682. end
  683. else if is_pwidechar(def_from) then
  684. begin
  685. doconv:=tc_pwchar_2_string;
  686. if is_wide_or_unicode_string(def_to) then
  687. eq:=te_convert_l1
  688. else
  689. { shortstring and ansistring can both result in
  690. data loss, so don't prefer one over the other }
  691. eq:=te_convert_l3;
  692. end;
  693. end;
  694. end;
  695. objectdef :
  696. begin
  697. { corba interface -> id string }
  698. if is_interfacecorba(def_from) then
  699. begin
  700. doconv:=tc_intf_2_string;
  701. eq:=te_convert_l1;
  702. end
  703. else if (def_from=java_jlstring) then
  704. begin
  705. if is_wide_or_unicode_string(def_to) then
  706. begin
  707. doconv:=tc_equal;
  708. eq:=te_equal;
  709. end
  710. else if def_to.typ=stringdef then
  711. begin
  712. doconv:=tc_string_2_string;
  713. if is_ansistring(def_to) then
  714. eq:=te_convert_l2
  715. else
  716. eq:=te_convert_l3
  717. end;
  718. end;
  719. end;
  720. end;
  721. end;
  722. floatdef :
  723. begin
  724. case def_from.typ of
  725. orddef :
  726. begin { ordinal to real }
  727. { only for implicit and internal typecasts in tp/delphi }
  728. if (([cdo_explicit,cdo_internal] * cdoptions <> [cdo_explicit]) or
  729. ([m_tp7,m_delphi] * current_settings.modeswitches = [])) and
  730. (is_integer(def_from) or
  731. (is_currency(def_from) and
  732. (s64currencytype.typ = floatdef))) then
  733. begin
  734. doconv:=tc_int_2_real;
  735. { prefer single over others }
  736. if is_single(def_to) then
  737. eq:=te_convert_l3
  738. else
  739. eq:=te_convert_l4;
  740. end
  741. else if is_currency(def_from)
  742. { and (s64currencytype.typ = orddef)) } then
  743. begin
  744. { prefer conversion to orddef in this case, unless }
  745. { the orddef < currency (then it will get convert l3, }
  746. { and conversion to float is favoured) }
  747. doconv:=tc_int_2_real;
  748. eq:=te_convert_l2;
  749. end;
  750. end;
  751. floatdef :
  752. begin
  753. if tfloatdef(def_from).floattype=tfloatdef(def_to).floattype then
  754. eq:=te_equal
  755. else
  756. begin
  757. { Delphi does not allow explicit type conversions for float types like:
  758. single_var:=single(double_var);
  759. But if such conversion is inserted by compiler (internal) for some purpose,
  760. it should be allowed even in Delphi mode. }
  761. if (fromtreetype=realconstn) or
  762. not((cdoptions*[cdo_explicit,cdo_internal]=[cdo_explicit]) and
  763. (m_delphi in current_settings.modeswitches)) then
  764. begin
  765. doconv:=tc_real_2_real;
  766. { do we lose precision? }
  767. if (def_to.size<def_from.size) or
  768. (is_currency(def_from) and (tfloatdef(def_to).floattype in [s32real,s64real])) then
  769. eq:=te_convert_l2
  770. else
  771. eq:=te_convert_l1;
  772. end;
  773. end;
  774. end;
  775. end;
  776. end;
  777. enumdef :
  778. begin
  779. case def_from.typ of
  780. enumdef :
  781. begin
  782. if cdo_explicit in cdoptions then
  783. begin
  784. eq:=te_convert_l1;
  785. doconv:=tc_int_2_int;
  786. end
  787. else
  788. begin
  789. hd1:=def_from;
  790. while assigned(tenumdef(hd1).basedef) do
  791. hd1:=tenumdef(hd1).basedef;
  792. hd2:=def_to;
  793. while assigned(tenumdef(hd2).basedef) do
  794. hd2:=tenumdef(hd2).basedef;
  795. if (hd1=hd2) then
  796. begin
  797. eq:=te_convert_l1;
  798. { because of packenum they can have different sizes! (JM) }
  799. doconv:=tc_int_2_int;
  800. end
  801. else
  802. begin
  803. { assignment of an enum symbol to an unique type? }
  804. if (fromtreetype=ordconstn) and
  805. (tenumsym(tenumdef(hd1).getfirstsym)=tenumsym(tenumdef(hd2).getfirstsym)) then
  806. begin
  807. { because of packenum they can have different sizes! (JM) }
  808. eq:=te_convert_l1;
  809. doconv:=tc_int_2_int;
  810. end;
  811. end;
  812. end;
  813. end;
  814. orddef :
  815. begin
  816. if cdo_explicit in cdoptions then
  817. begin
  818. eq:=te_convert_l1;
  819. doconv:=tc_int_2_int;
  820. end;
  821. end;
  822. variantdef :
  823. begin
  824. eq:=te_convert_l1;
  825. doconv:=tc_variant_2_enum;
  826. end;
  827. pointerdef :
  828. begin
  829. { ugly, but delphi allows it }
  830. if cdo_explicit in cdoptions then
  831. begin
  832. if target_info.system in systems_jvm then
  833. begin
  834. doconv:=tc_equal;
  835. eq:=te_convert_l1;
  836. end
  837. else if m_delphi in current_settings.modeswitches then
  838. begin
  839. doconv:=tc_int_2_int;
  840. eq:=te_convert_l1;
  841. end
  842. end;
  843. end;
  844. objectdef:
  845. begin
  846. { ugly, but delphi allows it }
  847. if (cdo_explicit in cdoptions) and
  848. is_class_or_interface_or_dispinterface_or_objc_or_java(def_from) then
  849. begin
  850. { in Java enums /are/ class instances, and hence such
  851. typecasts must not be treated as integer-like
  852. conversions
  853. }
  854. if target_info.system in systems_jvm then
  855. begin
  856. doconv:=tc_equal;
  857. eq:=te_convert_l1;
  858. end
  859. else if m_delphi in current_settings.modeswitches then
  860. begin
  861. doconv:=tc_int_2_int;
  862. eq:=te_convert_l1;
  863. end;
  864. end;
  865. end;
  866. end;
  867. end;
  868. arraydef :
  869. begin
  870. { open array is also compatible with a single element of its base type.
  871. the extra check for deftyp is needed because equal defs can also return
  872. true if the def types are not the same, for example with dynarray to pointer. }
  873. if is_open_array(def_to) and
  874. (def_from.typ=tarraydef(def_to).elementdef.typ) and
  875. equal_defs(def_from,tarraydef(def_to).elementdef) then
  876. begin
  877. doconv:=tc_elem_2_openarray;
  878. { also update in htypechk.pas/var_para_allowed if changed
  879. here }
  880. eq:=te_convert_l3;
  881. end
  882. else
  883. begin
  884. case def_from.typ of
  885. arraydef :
  886. begin
  887. { from/to packed array -- packed chararrays are }
  888. { strings in ISO Pascal (at least if the lower bound }
  889. { is 1, but GPC makes all equal-length chararrays }
  890. { compatible), so treat those the same as regular }
  891. { char arrays -- except if they use subrange types }
  892. if (is_packed_array(def_from) and
  893. (not is_chararray(def_from) or
  894. (tarraydef(def_from).elementdef.packedbitsize<>8)) and
  895. not is_widechararray(def_from)) xor
  896. (is_packed_array(def_to) and
  897. (not is_chararray(def_to) or
  898. (tarraydef(def_to).elementdef.packedbitsize<>8)) and
  899. not is_widechararray(def_to)) then
  900. { both must be packed }
  901. begin
  902. compare_defs_ext:=te_incompatible;
  903. exit;
  904. end
  905. { to dynamic array }
  906. else if is_dynamic_array(def_to) then
  907. begin
  908. if equal_defs(tarraydef(def_from).elementdef,tarraydef(def_to).elementdef) then
  909. begin
  910. { dynamic array -> dynamic array }
  911. if is_dynamic_array(def_from) then
  912. eq:=te_equal
  913. { fpc modes only: array -> dyn. array }
  914. else if (current_settings.modeswitches*[m_objfpc,m_fpc]<>[]) and
  915. not(is_special_array(def_from)) and
  916. is_zero_based_array(def_from) then
  917. begin
  918. eq:=te_convert_l2;
  919. doconv:=tc_array_2_dynarray;
  920. end;
  921. end
  922. end
  923. else
  924. { to open array }
  925. if is_open_array(def_to) then
  926. begin
  927. { array constructor -> open array }
  928. if is_array_constructor(def_from) then
  929. begin
  930. if is_void(tarraydef(def_from).elementdef) then
  931. begin
  932. doconv:=tc_equal;
  933. eq:=te_convert_l1;
  934. end
  935. else
  936. begin
  937. subeq:=compare_defs_ext(tarraydef(def_from).elementdef,
  938. tarraydef(def_to).elementdef,
  939. { reason for cdo_allow_variant: see webtbs/tw7070a and webtbs/tw7070b }
  940. arrayconstructorn,hct,hpd,[cdo_check_operator,cdo_allow_variant]);
  941. if (subeq>=te_equal) then
  942. begin
  943. doconv:=tc_equal;
  944. eq:=te_convert_l1;
  945. end
  946. else
  947. if (subeq>te_incompatible) then
  948. begin
  949. doconv:=hct;
  950. eq:=te_convert_l2;
  951. end;
  952. end;
  953. end
  954. else
  955. { dynamic array -> open array }
  956. if is_dynamic_array(def_from) and
  957. equal_defs(tarraydef(def_from).elementdef,tarraydef(def_to).elementdef) then
  958. begin
  959. doconv:=tc_dynarray_2_openarray;
  960. eq:=te_convert_l2;
  961. end
  962. else
  963. { open array -> open array }
  964. if is_open_array(def_from) and
  965. equal_defs(tarraydef(def_from).elementdef,tarraydef(def_to).elementdef) then
  966. if tarraydef(def_from).elementdef=tarraydef(def_to).elementdef then
  967. eq:=te_exact
  968. else
  969. eq:=te_equal
  970. else
  971. { array -> open array }
  972. if not(cdo_parameter in cdoptions) and
  973. equal_defs(tarraydef(def_from).elementdef,tarraydef(def_to).elementdef) then
  974. begin
  975. if fromtreetype=stringconstn then
  976. eq:=te_convert_l1
  977. else
  978. eq:=te_equal;
  979. end;
  980. end
  981. else
  982. { to array of const }
  983. if is_array_of_const(def_to) then
  984. begin
  985. if is_array_of_const(def_from) or
  986. is_array_constructor(def_from) then
  987. begin
  988. eq:=te_equal;
  989. end
  990. else
  991. { array of tvarrec -> array of const }
  992. if equal_defs(tarraydef(def_to).elementdef,tarraydef(def_from).elementdef) then
  993. begin
  994. doconv:=tc_equal;
  995. eq:=te_convert_l1;
  996. end;
  997. end
  998. else
  999. { to array of char, from "Untyped" stringconstn (array of char) }
  1000. if (fromtreetype=stringconstn) and
  1001. ((is_chararray(def_to) and
  1002. { bitpacked arrays of char whose element bitsize is not
  1003. 8 cannot be auto-converted from strings }
  1004. (not is_packed_array(def_to) or
  1005. (tarraydef(def_to).elementdef.packedbitsize=8))) or
  1006. is_widechararray(def_to)) then
  1007. begin
  1008. eq:=te_convert_l1;
  1009. doconv:=tc_string_2_chararray;
  1010. end
  1011. else
  1012. { other arrays }
  1013. begin
  1014. { open array -> array }
  1015. if not(cdo_parameter in cdoptions) and
  1016. is_open_array(def_from) and
  1017. equal_defs(tarraydef(def_from).elementdef,tarraydef(def_to).elementdef) then
  1018. begin
  1019. eq:=te_equal
  1020. end
  1021. else
  1022. { array -> array }
  1023. if not(m_tp7 in current_settings.modeswitches) and
  1024. not(m_delphi in current_settings.modeswitches) and
  1025. (tarraydef(def_from).lowrange=tarraydef(def_to).lowrange) and
  1026. (tarraydef(def_from).highrange=tarraydef(def_to).highrange) and
  1027. equal_defs(tarraydef(def_from).elementdef,tarraydef(def_to).elementdef) and
  1028. equal_defs(tarraydef(def_from).rangedef,tarraydef(def_to).rangedef) then
  1029. begin
  1030. eq:=te_equal
  1031. end;
  1032. end;
  1033. end;
  1034. pointerdef :
  1035. begin
  1036. { nil and voidpointers are compatible with dyn. arrays }
  1037. if is_dynamic_array(def_to) and
  1038. ((fromtreetype=niln) or
  1039. is_voidpointer(def_from)) then
  1040. begin
  1041. doconv:=tc_equal;
  1042. eq:=te_convert_l1;
  1043. end
  1044. else
  1045. if is_zero_based_array(def_to) and
  1046. equal_defs(tpointerdef(def_from).pointeddef,tarraydef(def_to).elementdef) then
  1047. begin
  1048. doconv:=tc_pointer_2_array;
  1049. eq:=te_convert_l1;
  1050. end;
  1051. end;
  1052. stringdef :
  1053. begin
  1054. { string to char array }
  1055. if not is_special_array(def_to) and
  1056. ((is_char(tarraydef(def_to).elementdef) and
  1057. { bitpacked arrays of char whose element bitsize is not
  1058. 8 cannot be auto-converted from strings }
  1059. (not is_packed_array(def_to) or
  1060. (tarraydef(def_to).elementdef.packedbitsize=8))) or
  1061. is_widechar(tarraydef(def_to).elementdef)) then
  1062. begin
  1063. doconv:=tc_string_2_chararray;
  1064. eq:=te_convert_l1;
  1065. end;
  1066. end;
  1067. orddef:
  1068. begin
  1069. if is_chararray(def_to) and
  1070. is_char(def_from) then
  1071. begin
  1072. doconv:=tc_char_2_chararray;
  1073. eq:=te_convert_l2;
  1074. end;
  1075. end;
  1076. recorddef :
  1077. begin
  1078. { tvarrec -> array of const }
  1079. if is_array_of_const(def_to) and
  1080. equal_defs(def_from,tarraydef(def_to).elementdef) then
  1081. begin
  1082. doconv:=tc_equal;
  1083. eq:=te_convert_l1;
  1084. end;
  1085. end;
  1086. variantdef :
  1087. begin
  1088. if is_dynamic_array(def_to) then
  1089. begin
  1090. doconv:=tc_variant_2_dynarray;
  1091. eq:=te_convert_l1;
  1092. end;
  1093. end;
  1094. end;
  1095. end;
  1096. end;
  1097. variantdef :
  1098. begin
  1099. if (cdo_allow_variant in cdoptions) then
  1100. begin
  1101. case def_from.typ of
  1102. enumdef :
  1103. begin
  1104. doconv:=tc_enum_2_variant;
  1105. eq:=te_convert_l1;
  1106. end;
  1107. arraydef :
  1108. begin
  1109. if is_dynamic_array(def_from) then
  1110. begin
  1111. doconv:=tc_dynarray_2_variant;
  1112. eq:=te_convert_l1;
  1113. end;
  1114. end;
  1115. objectdef :
  1116. begin
  1117. { corbainterfaces not accepted, until we have
  1118. runtime support for them in Variants (sergei) }
  1119. if is_interfacecom_or_dispinterface(def_from) then
  1120. begin
  1121. doconv:=tc_interface_2_variant;
  1122. eq:=te_convert_l1;
  1123. end;
  1124. end;
  1125. variantdef :
  1126. begin
  1127. { doing this in the compiler avoids a lot of unncessary
  1128. copying }
  1129. if (tvariantdef(def_from).varianttype=vt_olevariant) and
  1130. (tvariantdef(def_to).varianttype=vt_normalvariant) then
  1131. begin
  1132. doconv:=tc_equal;
  1133. eq:=te_convert_l1;
  1134. end;
  1135. end;
  1136. end;
  1137. end;
  1138. end;
  1139. pointerdef :
  1140. begin
  1141. case def_from.typ of
  1142. stringdef :
  1143. begin
  1144. { string constant (which can be part of array constructor)
  1145. to zero terminated string constant }
  1146. if (fromtreetype = stringconstn) and
  1147. (is_pchar(def_to) or is_pwidechar(def_to)) then
  1148. begin
  1149. doconv:=tc_cstring_2_pchar;
  1150. if is_pwidechar(def_to)=(m_default_unicodestring in current_settings.modeswitches) then
  1151. eq:=te_convert_l2
  1152. else
  1153. eq:=te_convert_l3
  1154. end
  1155. else
  1156. if (cdo_explicit in cdoptions) or (fromtreetype = arrayconstructorn) then
  1157. begin
  1158. { pchar(ansistring) }
  1159. if is_pchar(def_to) and
  1160. is_ansistring(def_from) then
  1161. begin
  1162. doconv:=tc_ansistring_2_pchar;
  1163. eq:=te_convert_l1;
  1164. end
  1165. else
  1166. { pwidechar(widestring) }
  1167. if is_pwidechar(def_to) and
  1168. is_wide_or_unicode_string(def_from) then
  1169. begin
  1170. doconv:=tc_ansistring_2_pchar;
  1171. eq:=te_convert_l1;
  1172. end;
  1173. end;
  1174. end;
  1175. orddef :
  1176. begin
  1177. { char constant to zero terminated string constant }
  1178. if (fromtreetype in [ordconstn,arrayconstructorn]) then
  1179. begin
  1180. if (is_char(def_from) or is_widechar(def_from)) and
  1181. (is_pchar(def_to) or is_pwidechar(def_to)) then
  1182. begin
  1183. doconv:=tc_cchar_2_pchar;
  1184. if is_pwidechar(def_to)=(m_default_unicodestring in current_settings.modeswitches) then
  1185. eq:=te_convert_l1
  1186. else
  1187. eq:=te_convert_l2
  1188. end
  1189. else
  1190. if (m_delphi in current_settings.modeswitches) and is_integer(def_from) then
  1191. begin
  1192. doconv:=tc_cord_2_pointer;
  1193. eq:=te_convert_l5;
  1194. end;
  1195. end;
  1196. { allow explicit typecasts from ordinals to pointer.
  1197. Support for delphi compatibility
  1198. Support constructs like pointer(cardinal-cardinal) or pointer(longint+cardinal) where
  1199. the result of the ordinal operation is int64 also on 32 bit platforms.
  1200. It is also used by the compiler internally for inc(pointer,ordinal) }
  1201. if (eq=te_incompatible) and
  1202. not is_void(def_from) and
  1203. (
  1204. (
  1205. (cdo_explicit in cdoptions) and
  1206. (
  1207. (m_delphi in current_settings.modeswitches) or
  1208. { Don't allow pchar(char) in fpc modes }
  1209. is_integer(def_from)
  1210. )
  1211. ) or
  1212. (cdo_internal in cdoptions)
  1213. ) then
  1214. begin
  1215. doconv:=tc_int_2_int;
  1216. eq:=te_convert_l1;
  1217. end;
  1218. end;
  1219. enumdef :
  1220. begin
  1221. { allow explicit typecasts from enums to pointer.
  1222. Support for delphi compatibility
  1223. }
  1224. { in Java enums /are/ class instances, and hence such
  1225. typecasts must not be treated as integer-like conversions
  1226. }
  1227. if (((cdo_explicit in cdoptions) and
  1228. ((m_delphi in current_settings.modeswitches) or
  1229. (target_info.system in systems_jvm)
  1230. )
  1231. ) or
  1232. (cdo_internal in cdoptions)
  1233. ) then
  1234. begin
  1235. { in Java enums /are/ class instances, and hence such
  1236. typecasts must not be treated as integer-like
  1237. conversions
  1238. }
  1239. if target_info.system in systems_jvm then
  1240. begin
  1241. doconv:=tc_equal;
  1242. eq:=te_convert_l1;
  1243. end
  1244. else if m_delphi in current_settings.modeswitches then
  1245. begin
  1246. doconv:=tc_int_2_int;
  1247. eq:=te_convert_l1;
  1248. end;
  1249. end;
  1250. end;
  1251. arraydef :
  1252. begin
  1253. { string constant (which can be part of array constructor)
  1254. to zero terminated string constant }
  1255. if (((fromtreetype = arrayconstructorn) and
  1256. { can't use is_chararray, because returns false for }
  1257. { array constructors }
  1258. is_char(tarraydef(def_from).elementdef)) or
  1259. (fromtreetype = stringconstn)) and
  1260. (is_pchar(def_to) or is_pwidechar(def_to)) then
  1261. begin
  1262. doconv:=tc_cstring_2_pchar;
  1263. if ((m_default_unicodestring in current_settings.modeswitches) xor
  1264. is_pchar(def_to)) then
  1265. eq:=te_convert_l2
  1266. else
  1267. eq:=te_convert_l3;
  1268. end
  1269. else
  1270. { chararray to pointer }
  1271. if (is_zero_based_array(def_from) or
  1272. is_open_array(def_from)) and
  1273. equal_defs(tarraydef(def_from).elementdef,tpointerdef(def_to).pointeddef) then
  1274. begin
  1275. doconv:=tc_array_2_pointer;
  1276. { don't prefer the pchar overload when a constant
  1277. string was passed }
  1278. if fromtreetype=stringconstn then
  1279. eq:=te_convert_l2
  1280. else
  1281. eq:=te_convert_l1;
  1282. end
  1283. else
  1284. { dynamic array to pointer, delphi only }
  1285. if (m_delphi in current_settings.modeswitches) and
  1286. is_dynamic_array(def_from) and
  1287. is_voidpointer(def_to) then
  1288. begin
  1289. eq:=te_equal;
  1290. end;
  1291. end;
  1292. pointerdef :
  1293. begin
  1294. {$ifdef x86}
  1295. { check for far pointers }
  1296. if (tcpupointerdef(def_from).x86pointertyp<>tcpupointerdef(def_to).x86pointertyp) then
  1297. begin
  1298. if fromtreetype=niln then
  1299. eq:=te_equal
  1300. else
  1301. eq:=te_incompatible;
  1302. end
  1303. else
  1304. {$endif x86}
  1305. { the types can be forward type, handle before normal type check !! }
  1306. if assigned(def_to.typesym) and
  1307. ((tpointerdef(def_to).pointeddef.typ=forwarddef) or
  1308. (tpointerdef(def_from).pointeddef.typ=forwarddef)) then
  1309. begin
  1310. if (def_from.typesym=def_to.typesym) or
  1311. (fromtreetype=niln) then
  1312. eq:=te_equal
  1313. end
  1314. else
  1315. { same types }
  1316. if equal_defs(tpointerdef(def_from).pointeddef,tpointerdef(def_to).pointeddef) then
  1317. begin
  1318. eq:=te_equal
  1319. end
  1320. else
  1321. { child class pointer can be assigned to anchestor pointers }
  1322. if (
  1323. (tpointerdef(def_from).pointeddef.typ=objectdef) and
  1324. (tpointerdef(def_to).pointeddef.typ=objectdef) and
  1325. def_is_related(tobjectdef(tpointerdef(def_from).pointeddef),
  1326. tobjectdef(tpointerdef(def_to).pointeddef))
  1327. ) then
  1328. begin
  1329. doconv:=tc_equal;
  1330. eq:=te_convert_l1;
  1331. end
  1332. else
  1333. { all pointers can be assigned to void-pointer }
  1334. if is_void(tpointerdef(def_to).pointeddef) then
  1335. begin
  1336. doconv:=tc_equal;
  1337. { give pwidechar,pchar a penalty so it prefers
  1338. conversion to ansistring }
  1339. if is_pchar(def_from) or
  1340. is_pwidechar(def_from) then
  1341. eq:=te_convert_l2
  1342. else
  1343. eq:=te_convert_l1;
  1344. end
  1345. else
  1346. { all pointers can be assigned from void-pointer }
  1347. if is_void(tpointerdef(def_from).pointeddef) or
  1348. { all pointers can be assigned from void-pointer or formaldef pointer, check
  1349. tw3777.pp if you change this }
  1350. (tpointerdef(def_from).pointeddef.typ=formaldef) then
  1351. begin
  1352. doconv:=tc_equal;
  1353. { give pwidechar a penalty so it prefers
  1354. conversion to pchar }
  1355. if is_pwidechar(def_to) then
  1356. eq:=te_convert_l2
  1357. else
  1358. eq:=te_convert_l1;
  1359. end
  1360. { id = generic class instance. metaclasses are also
  1361. class instances themselves. }
  1362. else if ((def_from=objc_idtype) and
  1363. (def_to=objc_metaclasstype)) or
  1364. ((def_to=objc_idtype) and
  1365. (def_from=objc_metaclasstype)) then
  1366. begin
  1367. doconv:=tc_equal;
  1368. eq:=te_convert_l2;
  1369. end;
  1370. end;
  1371. procvardef :
  1372. begin
  1373. { procedure variable can be assigned to an void pointer,
  1374. this is not allowed for complex procvars }
  1375. if (is_void(tpointerdef(def_to).pointeddef) or
  1376. (m_mac_procvar in current_settings.modeswitches)) and
  1377. tprocvardef(def_from).is_addressonly then
  1378. begin
  1379. doconv:=tc_equal;
  1380. eq:=te_convert_l1;
  1381. end;
  1382. end;
  1383. procdef :
  1384. begin
  1385. { procedure variable can be assigned to an void pointer,
  1386. this not allowed for methodpointers }
  1387. if (m_mac_procvar in current_settings.modeswitches) and
  1388. tprocdef(def_from).is_addressonly then
  1389. begin
  1390. doconv:=tc_proc_2_procvar;
  1391. eq:=te_convert_l2;
  1392. end;
  1393. end;
  1394. classrefdef,
  1395. objectdef :
  1396. begin
  1397. { implicit pointer object and class reference types
  1398. can be assigned to void pointers, but it is less
  1399. preferred than assigning to a related objectdef }
  1400. if (
  1401. is_implicit_pointer_object_type(def_from) or
  1402. (def_from.typ=classrefdef)
  1403. ) and
  1404. (tpointerdef(def_to).pointeddef.typ=orddef) and
  1405. (torddef(tpointerdef(def_to).pointeddef).ordtype=uvoid) then
  1406. begin
  1407. doconv:=tc_equal;
  1408. eq:=te_convert_l2;
  1409. end
  1410. else if (is_objc_class_or_protocol(def_from) and
  1411. (def_to=objc_idtype)) or
  1412. { classrefs are also instances in Objective-C,
  1413. hence they're also assignment-cpmpatible with
  1414. id }
  1415. (is_objcclassref(def_from) and
  1416. ((def_to=objc_metaclasstype) or
  1417. (def_to=objc_idtype))) then
  1418. begin
  1419. doconv:=tc_equal;
  1420. eq:=te_convert_l2;
  1421. end;
  1422. end;
  1423. end;
  1424. end;
  1425. setdef :
  1426. begin
  1427. case def_from.typ of
  1428. setdef :
  1429. begin
  1430. if assigned(tsetdef(def_from).elementdef) and
  1431. assigned(tsetdef(def_to).elementdef) then
  1432. begin
  1433. { sets with the same size (packset setting), element
  1434. base type and the same range are equal }
  1435. if equal_defs(tsetdef(def_from).elementdef,tsetdef(def_to).elementdef) and
  1436. (tsetdef(def_from).setbase=tsetdef(def_to).setbase) and
  1437. (tsetdef(def_from).setmax=tsetdef(def_to).setmax) and
  1438. (def_from.size=def_to.size) then
  1439. eq:=te_equal
  1440. else if is_subequal(tsetdef(def_from).elementdef,tsetdef(def_to).elementdef) then
  1441. begin
  1442. eq:=te_convert_l1;
  1443. doconv:=tc_set_to_set;
  1444. end;
  1445. end
  1446. else
  1447. begin
  1448. { empty set is compatible with everything }
  1449. eq:=te_convert_l1;
  1450. doconv:=tc_set_to_set;
  1451. end;
  1452. end;
  1453. arraydef :
  1454. begin
  1455. { automatic arrayconstructor -> set conversion }
  1456. if is_array_constructor(def_from) then
  1457. begin
  1458. doconv:=tc_arrayconstructor_2_set;
  1459. eq:=te_convert_l1;
  1460. end;
  1461. end;
  1462. end;
  1463. end;
  1464. procvardef :
  1465. begin
  1466. case def_from.typ of
  1467. procdef :
  1468. begin
  1469. { proc -> procvar }
  1470. if (m_tp_procvar in current_settings.modeswitches) or
  1471. (m_mac_procvar in current_settings.modeswitches) then
  1472. begin
  1473. subeq:=proc_to_procvar_equal(tprocdef(def_from),tprocvardef(def_to),cdo_warn_incompatible_univ in cdoptions);
  1474. if subeq>te_incompatible then
  1475. begin
  1476. doconv:=tc_proc_2_procvar;
  1477. if subeq>te_convert_l5 then
  1478. eq:=pred(subeq)
  1479. else
  1480. eq:=subeq;
  1481. end;
  1482. end;
  1483. end;
  1484. procvardef :
  1485. begin
  1486. { procvar -> procvar }
  1487. eq:=proc_to_procvar_equal(tprocvardef(def_from),tprocvardef(def_to),cdo_warn_incompatible_univ in cdoptions);
  1488. if eq<te_equal then
  1489. doconv:=tc_proc_2_procvar
  1490. else
  1491. doconv:=tc_equal;
  1492. end;
  1493. pointerdef :
  1494. begin
  1495. { nil is compatible with procvars }
  1496. if (fromtreetype=niln) then
  1497. begin
  1498. if not Tprocvardef(def_to).is_addressonly then
  1499. {Nil to method pointers requires to convert a single
  1500. pointer nil value to a two pointer procvardef.}
  1501. doconv:=tc_nil_2_methodprocvar
  1502. else
  1503. doconv:=tc_equal;
  1504. eq:=te_convert_l1;
  1505. end
  1506. else
  1507. { for example delphi allows the assignement from pointers }
  1508. { to procedure variables }
  1509. if (m_pointer_2_procedure in current_settings.modeswitches) and
  1510. is_void(tpointerdef(def_from).pointeddef) and
  1511. tprocvardef(def_to).is_addressonly then
  1512. begin
  1513. doconv:=tc_equal;
  1514. eq:=te_convert_l1;
  1515. end;
  1516. end;
  1517. end;
  1518. end;
  1519. objectdef :
  1520. begin
  1521. { object pascal objects }
  1522. if (def_from.typ=objectdef) and
  1523. (def_is_related(tobjectdef(def_from),tobjectdef(def_to))) then
  1524. begin
  1525. doconv:=tc_equal;
  1526. { also update in htypechk.pas/var_para_allowed if changed
  1527. here }
  1528. eq:=te_convert_l3;
  1529. end
  1530. { string -> java.lang.string }
  1531. else if (def_to=java_jlstring) and
  1532. ((def_from.typ=stringdef) or
  1533. (fromtreetype=stringconstn)) then
  1534. begin
  1535. if is_wide_or_unicode_string(def_from) or
  1536. ((fromtreetype=stringconstn) and
  1537. (cs_refcountedstrings in current_settings.localswitches) and
  1538. (m_default_unicodestring in current_settings.modeswitches)) then
  1539. begin
  1540. doconv:=tc_equal;
  1541. eq:=te_equal
  1542. end
  1543. else
  1544. begin
  1545. doconv:=tc_string_2_string;
  1546. eq:=te_convert_l2;
  1547. end;
  1548. end
  1549. else if (def_to=java_jlstring) and
  1550. is_anychar(def_from) then
  1551. begin
  1552. doconv:=tc_char_2_string;
  1553. eq:=te_convert_l2
  1554. end
  1555. else
  1556. { specific to implicit pointer object types }
  1557. if is_implicit_pointer_object_type(def_to) then
  1558. begin
  1559. { void pointer also for delphi mode }
  1560. if (m_delphi in current_settings.modeswitches) and
  1561. is_voidpointer(def_from) then
  1562. begin
  1563. doconv:=tc_equal;
  1564. { prefer pointer-pointer assignments }
  1565. eq:=te_convert_l2;
  1566. end
  1567. else
  1568. { nil is compatible with class instances and interfaces }
  1569. if (fromtreetype=niln) then
  1570. begin
  1571. doconv:=tc_equal;
  1572. eq:=te_convert_l1;
  1573. end
  1574. { All Objective-C classes are compatible with ID }
  1575. else if is_objc_class_or_protocol(def_to) and
  1576. (def_from=objc_idtype) then
  1577. begin
  1578. doconv:=tc_equal;
  1579. eq:=te_convert_l2;
  1580. end
  1581. { classes can be assigned to interfaces
  1582. (same with objcclass and objcprotocol) }
  1583. else if ((is_interface(def_to) and
  1584. is_class(def_from)) or
  1585. (is_objcprotocol(def_to) and
  1586. is_objcclass(def_from)) or
  1587. (is_javainterface(def_to) and
  1588. is_javaclass(def_from))) and
  1589. assigned(tobjectdef(def_from).ImplementedInterfaces) then
  1590. begin
  1591. { we've to search in parent classes as well }
  1592. hobjdef:=tobjectdef(def_from);
  1593. while assigned(hobjdef) do
  1594. begin
  1595. if find_implemented_interface(hobjdef,tobjectdef(def_to))<>nil then
  1596. begin
  1597. if is_interface(def_to) then
  1598. doconv:=tc_class_2_intf
  1599. else
  1600. { for Objective-C, we don't have to do anything special }
  1601. doconv:=tc_equal;
  1602. { don't prefer this over objectdef->objectdef }
  1603. eq:=te_convert_l2;
  1604. break;
  1605. end;
  1606. hobjdef:=hobjdef.childof;
  1607. end;
  1608. end
  1609. { Interface 2 GUID handling }
  1610. else if (def_to=tdef(rec_tguid)) and
  1611. (fromtreetype=typen) and
  1612. is_interface(def_from) and
  1613. assigned(tobjectdef(def_from).iidguid) then
  1614. begin
  1615. eq:=te_convert_l1;
  1616. doconv:=tc_equal;
  1617. end
  1618. else if (def_from.typ=variantdef) and is_interfacecom_or_dispinterface(def_to) then
  1619. begin
  1620. { corbainterfaces not accepted, until we have
  1621. runtime support for them in Variants (sergei) }
  1622. doconv:=tc_variant_2_interface;
  1623. eq:=te_convert_l2;
  1624. end
  1625. { ugly, but delphi allows it (enables typecasting ordinals/
  1626. enums of any size to pointer-based object defs) }
  1627. { in Java enums /are/ class instances, and hence such
  1628. typecasts must not be treated as integer-like conversions;
  1629. arbitrary constants cannot be converted into classes/
  1630. pointer-based values either on the JVM -> always return
  1631. false and let it be handled by the regular explicit type
  1632. casting code
  1633. }
  1634. else if (not(target_info.system in systems_jvm) and
  1635. ((def_from.typ=enumdef) or
  1636. (def_from.typ=orddef))) and
  1637. (m_delphi in current_settings.modeswitches) and
  1638. (cdo_explicit in cdoptions) then
  1639. begin
  1640. doconv:=tc_int_2_int;
  1641. eq:=te_convert_l1;
  1642. end;
  1643. end;
  1644. end;
  1645. classrefdef :
  1646. begin
  1647. { similar to pointerdef wrt forwards }
  1648. if assigned(def_to.typesym) and
  1649. (tclassrefdef(def_to).pointeddef.typ=forwarddef) or
  1650. ((def_from.typ=classrefdef) and
  1651. (tclassrefdef(def_from).pointeddef.typ=forwarddef)) then
  1652. begin
  1653. if (def_from.typesym=def_to.typesym) or
  1654. (fromtreetype=niln) then
  1655. eq:=te_equal;
  1656. end
  1657. else
  1658. { class reference types }
  1659. if (def_from.typ=classrefdef) then
  1660. begin
  1661. if equal_defs(tclassrefdef(def_from).pointeddef,tclassrefdef(def_to).pointeddef) then
  1662. begin
  1663. eq:=te_equal;
  1664. end
  1665. else
  1666. begin
  1667. doconv:=tc_equal;
  1668. if (cdo_explicit in cdoptions) or
  1669. def_is_related(tobjectdef(tclassrefdef(def_from).pointeddef),
  1670. tobjectdef(tclassrefdef(def_to).pointeddef)) then
  1671. eq:=te_convert_l1;
  1672. end;
  1673. end
  1674. else
  1675. if (m_delphi in current_settings.modeswitches) and
  1676. is_voidpointer(def_from) then
  1677. begin
  1678. doconv:=tc_equal;
  1679. { prefer pointer-pointer assignments }
  1680. eq:=te_convert_l2;
  1681. end
  1682. else
  1683. { nil is compatible with class references }
  1684. if (fromtreetype=niln) then
  1685. begin
  1686. doconv:=tc_equal;
  1687. eq:=te_convert_l1;
  1688. end
  1689. else
  1690. { id is compatible with all classref types }
  1691. if (def_from=objc_idtype) then
  1692. begin
  1693. doconv:=tc_equal;
  1694. eq:=te_convert_l1;
  1695. end;
  1696. end;
  1697. filedef :
  1698. begin
  1699. { typed files are all equal to the abstract file type
  1700. name TYPEDFILE in system.pp in is_equal in types.pas
  1701. the problem is that it sholud be also compatible to FILE
  1702. but this would leed to a problem for ASSIGN RESET and REWRITE
  1703. when trying to find the good overloaded function !!
  1704. so all file function are doubled in system.pp
  1705. this is not very beautiful !!}
  1706. if (def_from.typ=filedef) then
  1707. begin
  1708. if (tfiledef(def_from).filetyp=tfiledef(def_to).filetyp) then
  1709. begin
  1710. if
  1711. (
  1712. (tfiledef(def_from).typedfiledef=nil) and
  1713. (tfiledef(def_to).typedfiledef=nil)
  1714. ) or
  1715. (
  1716. (tfiledef(def_from).typedfiledef<>nil) and
  1717. (tfiledef(def_to).typedfiledef<>nil) and
  1718. equal_defs(tfiledef(def_from).typedfiledef,tfiledef(def_to).typedfiledef)
  1719. ) or
  1720. (
  1721. (tfiledef(def_from).filetyp = ft_typed) and
  1722. (tfiledef(def_to).filetyp = ft_typed) and
  1723. (
  1724. (tfiledef(def_from).typedfiledef = tdef(voidtype)) or
  1725. (tfiledef(def_to).typedfiledef = tdef(voidtype))
  1726. )
  1727. ) then
  1728. begin
  1729. eq:=te_equal;
  1730. end;
  1731. end
  1732. else
  1733. if ((tfiledef(def_from).filetyp = ft_untyped) and
  1734. (tfiledef(def_to).filetyp = ft_typed)) or
  1735. ((tfiledef(def_from).filetyp = ft_typed) and
  1736. (tfiledef(def_to).filetyp = ft_untyped)) then
  1737. begin
  1738. doconv:=tc_equal;
  1739. eq:=te_convert_l1;
  1740. end;
  1741. end;
  1742. end;
  1743. recorddef :
  1744. begin
  1745. { interface -> guid }
  1746. if (def_to=rec_tguid) and
  1747. (is_interfacecom_or_dispinterface(def_from)) then
  1748. begin
  1749. doconv:=tc_intf_2_guid;
  1750. eq:=te_convert_l1;
  1751. end;
  1752. end;
  1753. formaldef :
  1754. begin
  1755. doconv:=tc_equal;
  1756. if (def_from.typ=formaldef) then
  1757. eq:=te_equal
  1758. else
  1759. { Just about everything can be converted to a formaldef...}
  1760. if not (def_from.typ in [abstractdef,errordef]) then
  1761. eq:=te_convert_l2;
  1762. end;
  1763. end;
  1764. { if we didn't find an appropriate type conversion yet
  1765. then we search also the := operator }
  1766. if (eq=te_incompatible) and
  1767. { make sure there is not a single variant if variants }
  1768. { are not allowed (otherwise if only cdo_check_operator }
  1769. { and e.g. fromdef=stringdef and todef=variantdef, then }
  1770. { the test will still succeed }
  1771. ((cdo_allow_variant in cdoptions) or
  1772. ((def_from.typ<>variantdef) and
  1773. (def_to.typ<>variantdef) and
  1774. { internal typeconversions always have to be bitcasts (except for
  1775. variants) }
  1776. not(cdo_internal in cdoptions)
  1777. )
  1778. ) and
  1779. (
  1780. { Check for variants? }
  1781. (
  1782. (cdo_allow_variant in cdoptions) and
  1783. ((def_from.typ=variantdef) or (def_to.typ=variantdef))
  1784. ) or
  1785. { Check for operators? }
  1786. (
  1787. (cdo_check_operator in cdoptions) and
  1788. ((def_from.typ<>variantdef) or (def_to.typ<>variantdef))
  1789. )
  1790. ) then
  1791. begin
  1792. operatorpd:=search_assignment_operator(def_from,def_to,cdo_explicit in cdoptions);
  1793. if assigned(operatorpd) then
  1794. eq:=te_convert_operator;
  1795. end;
  1796. { update convtype for te_equal when it is not yet set }
  1797. if (eq=te_equal) and
  1798. (doconv=tc_not_possible) then
  1799. doconv:=tc_equal;
  1800. compare_defs_ext:=eq;
  1801. end;
  1802. function equal_defs(def_from,def_to:tdef):boolean;
  1803. var
  1804. convtyp : tconverttype;
  1805. pd : tprocdef;
  1806. begin
  1807. { Compare defs with nothingn and no explicit typecasts and
  1808. searching for overloaded operators is not needed }
  1809. equal_defs:=(compare_defs_ext(def_from,def_to,nothingn,convtyp,pd,[])>=te_equal);
  1810. end;
  1811. function compare_defs(def_from,def_to:tdef;fromtreetype:tnodetype):tequaltype;
  1812. var
  1813. doconv : tconverttype;
  1814. pd : tprocdef;
  1815. begin
  1816. compare_defs:=compare_defs_ext(def_from,def_to,fromtreetype,doconv,pd,[cdo_check_operator,cdo_allow_variant]);
  1817. end;
  1818. function is_subequal(def1, def2: tdef): boolean;
  1819. var
  1820. basedef1,basedef2 : tenumdef;
  1821. Begin
  1822. is_subequal := false;
  1823. if assigned(def1) and assigned(def2) then
  1824. Begin
  1825. if (def1.typ = orddef) and (def2.typ = orddef) then
  1826. Begin
  1827. { see p.47 of Turbo Pascal 7.01 manual for the separation of types }
  1828. { range checking for case statements is done with testrange }
  1829. case torddef(def1).ordtype of
  1830. u8bit,u16bit,u32bit,u64bit,
  1831. s8bit,s16bit,s32bit,s64bit :
  1832. is_subequal:=(torddef(def2).ordtype in [s64bit,u64bit,s32bit,u32bit,u8bit,s8bit,s16bit,u16bit]);
  1833. pasbool8,pasbool16,pasbool32,pasbool64,
  1834. bool8bit,bool16bit,bool32bit,bool64bit :
  1835. is_subequal:=(torddef(def2).ordtype in [pasbool8,pasbool16,pasbool32,pasbool64,bool8bit,bool16bit,bool32bit,bool64bit]);
  1836. uchar :
  1837. is_subequal:=(torddef(def2).ordtype=uchar);
  1838. uwidechar :
  1839. is_subequal:=(torddef(def2).ordtype=uwidechar);
  1840. end;
  1841. end
  1842. else
  1843. Begin
  1844. { Check if both basedefs are equal }
  1845. if (def1.typ=enumdef) and (def2.typ=enumdef) then
  1846. Begin
  1847. { get both basedefs }
  1848. basedef1:=tenumdef(def1);
  1849. while assigned(basedef1.basedef) do
  1850. basedef1:=basedef1.basedef;
  1851. basedef2:=tenumdef(def2);
  1852. while assigned(basedef2.basedef) do
  1853. basedef2:=basedef2.basedef;
  1854. is_subequal:=(basedef1=basedef2);
  1855. end;
  1856. end;
  1857. end;
  1858. end;
  1859. function potentially_incompatible_univ_paras(def1, def2: tdef): boolean;
  1860. begin
  1861. result :=
  1862. { not entirely safe: different records can be passed differently
  1863. depending on the types of their fields, but they're hard to compare
  1864. (variant records, bitpacked vs non-bitpacked) }
  1865. ((def1.typ in [floatdef,recorddef,arraydef,filedef,variantdef]) and
  1866. (def1.typ<>def2.typ)) or
  1867. { pointers, ordinals and small sets are all passed the same}
  1868. (((def1.typ in [orddef,enumdef,pointerdef,procvardef,classrefdef]) or
  1869. (is_class_or_interface_or_objc(def1)) or
  1870. is_dynamic_array(def1) or
  1871. is_smallset(def1) or
  1872. is_ansistring(def1) or
  1873. is_unicodestring(def1)) <>
  1874. (def2.typ in [orddef,enumdef,pointerdef,procvardef,classrefdef]) or
  1875. (is_class_or_interface_or_objc(def2)) or
  1876. is_dynamic_array(def2) or
  1877. is_smallset(def2) or
  1878. is_ansistring(def2) or
  1879. is_unicodestring(def2)) or
  1880. { shortstrings }
  1881. (is_shortstring(def1)<>
  1882. is_shortstring(def2)) or
  1883. { winlike widestrings }
  1884. (is_widestring(def1)<>
  1885. is_widestring(def2)) or
  1886. { TP-style objects }
  1887. (is_object(def1) <>
  1888. is_object(def2));
  1889. end;
  1890. function compare_paras(para1,para2 : TFPObjectList; acp : tcompare_paras_type; cpoptions: tcompare_paras_options):tequaltype;
  1891. var
  1892. currpara1,
  1893. currpara2 : tparavarsym;
  1894. eq,lowesteq : tequaltype;
  1895. hpd : tprocdef;
  1896. convtype : tconverttype;
  1897. cdoptions : tcompare_defs_options;
  1898. i1,i2 : byte;
  1899. begin
  1900. compare_paras:=te_incompatible;
  1901. cdoptions:=[cdo_parameter,cdo_check_operator,cdo_allow_variant,cdo_strict_undefined_check];
  1902. { we need to parse the list from left-right so the
  1903. not-default parameters are checked first }
  1904. lowesteq:=high(tequaltype);
  1905. i1:=0;
  1906. i2:=0;
  1907. if cpo_ignorehidden in cpoptions then
  1908. begin
  1909. while (i1<para1.count) and
  1910. (vo_is_hidden_para in tparavarsym(para1[i1]).varoptions) do
  1911. inc(i1);
  1912. while (i2<para2.count) and
  1913. (vo_is_hidden_para in tparavarsym(para2[i2]).varoptions) do
  1914. inc(i2);
  1915. end;
  1916. if cpo_ignoreframepointer in cpoptions then
  1917. begin
  1918. if (i1<para1.count) and
  1919. (vo_is_parentfp in tparavarsym(para1[i1]).varoptions) then
  1920. inc(i1);
  1921. if (i2<para2.count) and
  1922. (vo_is_parentfp in tparavarsym(para2[i2]).varoptions) then
  1923. inc(i2);
  1924. end;
  1925. while (i1<para1.count) and (i2<para2.count) do
  1926. begin
  1927. eq:=te_incompatible;
  1928. currpara1:=tparavarsym(para1[i1]);
  1929. currpara2:=tparavarsym(para2[i2]);
  1930. { Unique types must match exact }
  1931. if ((df_unique in currpara1.vardef.defoptions) or (df_unique in currpara2.vardef.defoptions)) and
  1932. (currpara1.vardef<>currpara2.vardef) then
  1933. exit;
  1934. { Handle hidden parameters separately, because self is
  1935. defined as voidpointer for methodpointers }
  1936. if (vo_is_hidden_para in currpara1.varoptions) or
  1937. (vo_is_hidden_para in currpara2.varoptions) then
  1938. begin
  1939. { both must be hidden }
  1940. if (vo_is_hidden_para in currpara1.varoptions)<>(vo_is_hidden_para in currpara2.varoptions) then
  1941. exit;
  1942. eq:=te_exact;
  1943. if not(vo_is_self in currpara1.varoptions) and
  1944. not(vo_is_self in currpara2.varoptions) then
  1945. begin
  1946. if not(cpo_ignorevarspez in cpoptions) and
  1947. (currpara1.varspez<>currpara2.varspez) then
  1948. exit;
  1949. eq:=compare_defs_ext(currpara1.vardef,currpara2.vardef,nothingn,
  1950. convtype,hpd,cdoptions);
  1951. end;
  1952. end
  1953. else
  1954. begin
  1955. case acp of
  1956. cp_value_equal_const :
  1957. begin
  1958. { this one is used for matching parameters from a call
  1959. statement to a procdef -> univ state can't be equal
  1960. in any case since the call statement does not contain
  1961. any information about that }
  1962. if (
  1963. not(cpo_ignorevarspez in cpoptions) and
  1964. (currpara1.varspez<>currpara2.varspez) and
  1965. ((currpara1.varspez in [vs_var,vs_out,vs_constref]) or
  1966. (currpara2.varspez in [vs_var,vs_out,vs_constref]))
  1967. ) then
  1968. exit;
  1969. eq:=compare_defs_ext(currpara1.vardef,currpara2.vardef,nothingn,
  1970. convtype,hpd,cdoptions);
  1971. end;
  1972. cp_all :
  1973. begin
  1974. { used to resolve forward definitions -> headers must
  1975. match exactly, including the "univ" specifier }
  1976. if (not(cpo_ignorevarspez in cpoptions) and
  1977. (currpara1.varspez<>currpara2.varspez)) or
  1978. (currpara1.univpara<>currpara2.univpara) then
  1979. exit;
  1980. eq:=compare_defs_ext(currpara1.vardef,currpara2.vardef,nothingn,
  1981. convtype,hpd,cdoptions);
  1982. end;
  1983. cp_procvar :
  1984. begin
  1985. if not(cpo_ignorevarspez in cpoptions) and
  1986. (currpara1.varspez<>currpara2.varspez) then
  1987. exit;
  1988. { "univ" state doesn't matter here: from univ to non-univ
  1989. matches if the types are compatible (i.e., as usual),
  1990. from from non-univ to univ also matches if the types
  1991. have the same size (checked below) }
  1992. eq:=compare_defs_ext(currpara1.vardef,currpara2.vardef,nothingn,
  1993. convtype,hpd,cdoptions);
  1994. { Parameters must be at least equal otherwise the are incompatible }
  1995. if (eq<te_equal) then
  1996. eq:=te_incompatible;
  1997. end;
  1998. else
  1999. eq:=compare_defs_ext(currpara1.vardef,currpara2.vardef,nothingn,
  2000. convtype,hpd,cdoptions);
  2001. end;
  2002. end;
  2003. { check type }
  2004. if eq=te_incompatible then
  2005. begin
  2006. { special case: "univ" parameters match if their size is equal }
  2007. if not(cpo_ignoreuniv in cpoptions) and
  2008. currpara2.univpara and
  2009. is_valid_univ_para_type(currpara1.vardef) and
  2010. (currpara1.vardef.size=currpara2.vardef.size) then
  2011. begin
  2012. { only pick as last choice }
  2013. eq:=te_convert_l5;
  2014. if (acp=cp_procvar) and
  2015. (cpo_warn_incompatible_univ in cpoptions) then
  2016. begin
  2017. { if the types may be passed in different ways by the
  2018. calling convention then this can lead to crashes
  2019. (note: not an exhaustive check, and failing this
  2020. this check does not mean things will crash on all
  2021. platforms) }
  2022. if potentially_incompatible_univ_paras(currpara1.vardef,currpara2.vardef) then
  2023. Message2(type_w_procvar_univ_conflicting_para,currpara1.vardef.typename,currpara2.vardef.typename)
  2024. end;
  2025. end
  2026. else
  2027. exit;
  2028. end;
  2029. { open strings can never match exactly, since you cannot define }
  2030. { a separate "open string" type -> we have to be able to }
  2031. { consider those as exact when resolving forward definitions. }
  2032. { The same goes for array of const. Open arrays are handled }
  2033. { already (if their element types match exactly, they are }
  2034. { considered to be an exact match) }
  2035. { And also for "inline defined" function parameter definitions }
  2036. { (i.e., function types directly declared in a parameter list) }
  2037. if (is_array_of_const(currpara1.vardef) or
  2038. is_open_string(currpara1.vardef) or
  2039. ((currpara1.vardef.typ = procvardef) and
  2040. not(assigned(currpara1.vardef.typesym)))) and
  2041. (eq=te_equal) and
  2042. (cpo_openequalisexact in cpoptions) then
  2043. eq:=te_exact;
  2044. if eq<lowesteq then
  2045. lowesteq:=eq;
  2046. { also check default value if both have it declared }
  2047. if (cpo_comparedefaultvalue in cpoptions) then
  2048. begin
  2049. if assigned(currpara1.defaultconstsym) and
  2050. assigned(currpara2.defaultconstsym) then
  2051. begin
  2052. if not equal_constsym(tconstsym(currpara1.defaultconstsym),tconstsym(currpara2.defaultconstsym)) then
  2053. exit;
  2054. end
  2055. { cannot have that the second (= implementation) has a default value declared and the
  2056. other (interface) doesn't }
  2057. else if not assigned(currpara1.defaultconstsym) and assigned(currpara2.defaultconstsym) then
  2058. exit;
  2059. end;
  2060. if not(cpo_compilerproc in cpoptions) and
  2061. not(cpo_rtlproc in cpoptions) and
  2062. is_ansistring(currpara1.vardef) and
  2063. is_ansistring(currpara2.vardef) and
  2064. (tstringdef(currpara1.vardef).encoding<>tstringdef(currpara2.vardef).encoding) and
  2065. ((tstringdef(currpara1.vardef).encoding=globals.CP_NONE) or
  2066. (tstringdef(currpara2.vardef).encoding=globals.CP_NONE)
  2067. ) then
  2068. eq:=te_convert_l1;
  2069. if eq<lowesteq then
  2070. lowesteq:=eq;
  2071. inc(i1);
  2072. inc(i2);
  2073. if cpo_ignorehidden in cpoptions then
  2074. begin
  2075. while (i1<para1.count) and
  2076. (vo_is_hidden_para in tparavarsym(para1[i1]).varoptions) do
  2077. inc(i1);
  2078. while (i2<para2.count) and
  2079. (vo_is_hidden_para in tparavarsym(para2[i2]).varoptions) do
  2080. inc(i2);
  2081. end;
  2082. if cpo_ignoreframepointer in cpoptions then
  2083. begin
  2084. if (i1<para1.count) and
  2085. (vo_is_parentfp in tparavarsym(para1[i1]).varoptions) then
  2086. inc(i1);
  2087. if (i2<para2.count) and
  2088. (vo_is_parentfp in tparavarsym(para2[i2]).varoptions) then
  2089. inc(i2);
  2090. end;
  2091. end;
  2092. { when both lists are empty then the parameters are equal. Also
  2093. when one list is empty and the other has a parameter with default
  2094. value assigned then the parameters are also equal }
  2095. if ((i1>=para1.count) and (i2>=para2.count)) or
  2096. ((cpo_allowdefaults in cpoptions) and
  2097. (((i1<para1.count) and assigned(tparavarsym(para1[i1]).defaultconstsym)) or
  2098. ((i2<para2.count) and assigned(tparavarsym(para2[i2]).defaultconstsym)))) then
  2099. compare_paras:=lowesteq;
  2100. end;
  2101. function proc_to_procvar_equal(def1:tabstractprocdef;def2:tprocvardef;checkincompatibleuniv: boolean):tequaltype;
  2102. var
  2103. eq: tequaltype;
  2104. po_comp: tprocoptions;
  2105. pa_comp: tcompare_paras_options;
  2106. begin
  2107. proc_to_procvar_equal:=te_incompatible;
  2108. if not(assigned(def1)) or not(assigned(def2)) then
  2109. exit;
  2110. { check for method pointer and local procedure pointer:
  2111. a) anything but procvars can be assigned to blocks
  2112. b) if one is a procedure of object, the other also has to be one
  2113. (except for block)
  2114. c) if one is a pure address, the other also has to be one
  2115. except if def1 is a global proc and def2 is a nested procdef
  2116. (global procedures can be converted into nested procvars)
  2117. d) if def1 is a nested procedure, then def2 has to be a nested
  2118. procvar and def1 has to have the po_delphi_nested_cc option
  2119. e) if def1 is a procvar, def1 and def2 both have to be nested or
  2120. non-nested (we don't allow assignments from non-nested to
  2121. nested procvars to make sure that we can still implement
  2122. nested procvars using trampolines -- e.g., this would be
  2123. necessary for LLVM or CIL as long as they do not have support
  2124. for Delphi-style frame pointer parameter passing) }
  2125. if is_block(def2) then { a) }
  2126. { can't explicitly check against procvars here, because
  2127. def1 may already be a procvar due to a proc_to_procvar;
  2128. this is checked in the type conversion node itself -> ok }
  2129. else if (def1.is_methodpointer<>def2.is_methodpointer) or { b) }
  2130. ((def1.is_addressonly<>def2.is_addressonly) and { c) }
  2131. (is_nested_pd(def1) or
  2132. not is_nested_pd(def2))) or
  2133. ((def1.typ=procdef) and { d) }
  2134. is_nested_pd(def1) and
  2135. (not(po_delphi_nested_cc in def1.procoptions) or
  2136. not is_nested_pd(def2))) or
  2137. ((def1.typ=procvardef) and { e) }
  2138. (is_nested_pd(def1)<>is_nested_pd(def2))) then
  2139. exit;
  2140. pa_comp:=[cpo_ignoreframepointer];
  2141. if is_block(def2) then
  2142. include(pa_comp,cpo_ignorehidden);
  2143. if checkincompatibleuniv then
  2144. include(pa_comp,cpo_warn_incompatible_univ);
  2145. { check return value and options, methodpointer is already checked }
  2146. po_comp:=[po_interrupt,po_iocheck,po_varargs];
  2147. { check static only if we compare method pointers }
  2148. if def1.is_methodpointer then
  2149. include(po_comp,po_staticmethod);
  2150. if (m_delphi in current_settings.modeswitches) then
  2151. exclude(po_comp,po_varargs);
  2152. { for blocks, the calling convention doesn't matter because we have to
  2153. generate a wrapper anyway }
  2154. if ((po_is_block in def2.procoptions) or
  2155. (def1.proccalloption=def2.proccalloption)) and
  2156. ((po_comp * def1.procoptions)= (po_comp * def2.procoptions)) and
  2157. equal_defs(def1.returndef,def2.returndef) then
  2158. begin
  2159. { return equal type based on the parameters, but a proc->procvar
  2160. is never exact, so map an exact match of the parameters to
  2161. te_equal }
  2162. eq:=compare_paras(def1.paras,def2.paras,cp_procvar,pa_comp);
  2163. if eq=te_exact then
  2164. eq:=te_equal;
  2165. if (eq=te_equal) then
  2166. begin
  2167. { prefer non-nested to non-nested over non-nested to nested }
  2168. if (is_nested_pd(def1)<>is_nested_pd(def2)) then
  2169. eq:=te_convert_l1;
  2170. { in case of non-block to block, we need a type conversion }
  2171. if (po_is_block in def1.procoptions) <> (po_is_block in def2.procoptions) then
  2172. eq:=te_convert_l1;
  2173. end;
  2174. proc_to_procvar_equal:=eq;
  2175. end;
  2176. end;
  2177. function compatible_childmethod_resultdef(parentretdef, childretdef: tdef): boolean;
  2178. begin
  2179. compatible_childmethod_resultdef :=
  2180. (equal_defs(parentretdef,childretdef)) or
  2181. ((parentretdef.typ=objectdef) and
  2182. (childretdef.typ=objectdef) and
  2183. is_class_or_interface_or_objc_or_java(parentretdef) and
  2184. is_class_or_interface_or_objc_or_java(childretdef) and
  2185. (def_is_related(tobjectdef(childretdef),tobjectdef(parentretdef))))
  2186. end;
  2187. function find_implemented_interface(impldef,intfdef:tobjectdef):timplementedinterface;
  2188. var
  2189. implintf : timplementedinterface;
  2190. i : longint;
  2191. begin
  2192. if not assigned(impldef) then
  2193. internalerror(2013102301);
  2194. if not assigned(intfdef) then
  2195. internalerror(2013102302);
  2196. result:=nil;
  2197. if not assigned(impldef.implementedinterfaces) then
  2198. exit;
  2199. for i:=0 to impldef.implementedinterfaces.count-1 do
  2200. begin
  2201. implintf:=timplementedinterface(impldef.implementedinterfaces[i]);
  2202. if equal_defs(implintf.intfdef,intfdef) then
  2203. begin
  2204. result:=implintf;
  2205. exit;
  2206. end;
  2207. end;
  2208. end;
  2209. function stringdef_is_related(curdef:tstringdef;otherdef:tdef):boolean;
  2210. begin
  2211. result:=
  2212. (target_info.system in systems_jvm) and
  2213. (((curdef.stringtype in [st_unicodestring,st_widestring]) and
  2214. ((otherdef=java_jlobject) or
  2215. (otherdef=java_jlstring))) or
  2216. ((curdef.stringtype=st_ansistring) and
  2217. ((otherdef=java_jlobject) or
  2218. (otherdef=java_ansistring))));
  2219. end;
  2220. function recorddef_is_related(curdef:trecorddef;otherdef:tdef):boolean;
  2221. begin
  2222. { records are implemented via classes in the JVM target, and are
  2223. all descendents of the java_fpcbaserecordtype class }
  2224. result:=false;
  2225. if (target_info.system in systems_jvm) then
  2226. begin
  2227. if otherdef.typ=objectdef then
  2228. begin
  2229. otherdef:=find_real_class_definition(tobjectdef(otherdef),false);
  2230. if (otherdef=java_jlobject) or
  2231. (otherdef=java_fpcbaserecordtype) then
  2232. result:=true
  2233. end;
  2234. end;
  2235. end;
  2236. { true if prot implements d (or if they are equal) }
  2237. function is_related_interface_multiple(prot:tobjectdef;d:tdef):boolean;
  2238. var
  2239. i : longint;
  2240. begin
  2241. { objcprotocols have multiple inheritance, all protocols from which
  2242. the current protocol inherits are stored in implementedinterfaces }
  2243. result:=prot=d;
  2244. if result then
  2245. exit;
  2246. for i:=0 to prot.implementedinterfaces.count-1 do
  2247. begin
  2248. result:=is_related_interface_multiple(timplementedinterface(prot.implementedinterfaces[i]).intfdef,d);
  2249. if result then
  2250. exit;
  2251. end;
  2252. end;
  2253. function objectdef_is_related(curdef:tobjectdef;otherdef:tdef):boolean;
  2254. var
  2255. realself,
  2256. hp : tobjectdef;
  2257. begin
  2258. if (otherdef.typ=objectdef) then
  2259. otherdef:=find_real_class_definition(tobjectdef(otherdef),false);
  2260. realself:=find_real_class_definition(curdef,false);
  2261. if realself=otherdef then
  2262. begin
  2263. result:=true;
  2264. exit;
  2265. end;
  2266. if (otherdef.typ<>objectdef) then
  2267. begin
  2268. result:=false;
  2269. exit;
  2270. end;
  2271. { Objective-C protocols and Java interfaces can use multiple
  2272. inheritance }
  2273. if (realself.objecttype in [odt_objcprotocol,odt_interfacejava]) then
  2274. begin
  2275. result:=is_related_interface_multiple(realself,otherdef);
  2276. exit;
  2277. end;
  2278. { formally declared Objective-C and Java classes match Objective-C/Java
  2279. classes with the same name. In case of Java, the package must also
  2280. match (still required even though we looked up the real definitions
  2281. above, because these may be two different formal declarations that
  2282. cannot be resolved yet) }
  2283. if (realself.objecttype in [odt_objcclass,odt_javaclass]) and
  2284. (tobjectdef(otherdef).objecttype=curdef.objecttype) and
  2285. ((oo_is_formal in curdef.objectoptions) or
  2286. (oo_is_formal in tobjectdef(otherdef).objectoptions)) and
  2287. (curdef.objrealname^=tobjectdef(otherdef).objrealname^) then
  2288. begin
  2289. { check package name for Java }
  2290. if curdef.objecttype=odt_objcclass then
  2291. result:=true
  2292. else
  2293. begin
  2294. result:=
  2295. assigned(curdef.import_lib)=assigned(tobjectdef(otherdef).import_lib);
  2296. if result and
  2297. assigned(curdef.import_lib) then
  2298. result:=curdef.import_lib^=tobjectdef(otherdef).import_lib^;
  2299. end;
  2300. exit;
  2301. end;
  2302. hp:=realself.childof;
  2303. while assigned(hp) do
  2304. begin
  2305. if equal_defs(hp,otherdef) then
  2306. begin
  2307. result:=true;
  2308. exit;
  2309. end;
  2310. hp:=hp.childof;
  2311. end;
  2312. result:=false;
  2313. end;
  2314. function def_is_related(curdef,otherdef:tdef):boolean;
  2315. begin
  2316. if not assigned(curdef) then
  2317. internalerror(2013102303);
  2318. case curdef.typ of
  2319. stringdef:
  2320. result:=stringdef_is_related(tstringdef(curdef),otherdef);
  2321. recorddef:
  2322. result:=recorddef_is_related(trecorddef(curdef),otherdef);
  2323. objectdef:
  2324. result:=objectdef_is_related(tobjectdef(curdef),otherdef);
  2325. else
  2326. result:=false;
  2327. end;
  2328. end;
  2329. end.