defcmp.pas 59 KB

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