types.pas 80 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239
  1. {
  2. $Id$
  3. Copyright (C) 1998-2000 by Florian Klaempfl
  4. This unit provides some help routines for type handling
  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 types;
  19. {$i defines.inc}
  20. interface
  21. uses
  22. cclasses,
  23. cpuinfo,
  24. globals,
  25. node,
  26. symconst,symbase,symtype,symdef,symsym;
  27. type
  28. tmmxtype = (mmxno,mmxu8bit,mmxs8bit,mmxu16bit,mmxs16bit,
  29. mmxu32bit,mmxs32bit,mmxfixed16,mmxsingle);
  30. const
  31. {# true if we must never copy this parameter }
  32. never_copy_const_param : boolean = false;
  33. {*****************************************************************************
  34. Basic type functions
  35. *****************************************************************************}
  36. {# Returns true, if def defines an ordinal type }
  37. function is_ordinal(def : tdef) : boolean;
  38. {# Returns the min. value of the type }
  39. function get_min_value(def : tdef) : TConstExprInt;
  40. {# Returns basetype of the specified range }
  41. function range_to_basetype(low,high:TConstExprInt):tbasetype;
  42. {# Returns true, if def defines an ordinal type }
  43. function is_integer(def : tdef) : boolean;
  44. {# Returns true if p is a boolean }
  45. function is_boolean(def : tdef) : boolean;
  46. {# Returns true if p is a char }
  47. function is_char(def : tdef) : boolean;
  48. {# Returns true if p is a widechar }
  49. function is_widechar(def : tdef) : boolean;
  50. {# Returns true if p is a void}
  51. function is_void(def : tdef) : boolean;
  52. {# Returns true if p is a smallset def }
  53. function is_smallset(p : tdef) : boolean;
  54. {# Returns true, if def defines a signed data type (only for ordinal types) }
  55. function is_signed(def : tdef) : boolean;
  56. {# Returns true whether def_from's range is comprised in def_to's if both are
  57. orddefs, false otherwise }
  58. function is_in_limit(def_from,def_to : tdef) : boolean;
  59. {*****************************************************************************
  60. Array helper functions
  61. *****************************************************************************}
  62. {# Returns true, if p points to a zero based (non special like open or
  63. dynamic array def).
  64. This is mainly used to see if the array
  65. is convertable to a pointer
  66. }
  67. function is_zero_based_array(p : tdef) : boolean;
  68. {# Returns true if p points to an open array def }
  69. function is_open_array(p : tdef) : boolean;
  70. {# Returns true if p points to a dynamic array def }
  71. function is_dynamic_array(p : tdef) : boolean;
  72. {# Returns true, if p points to an array of const def }
  73. function is_array_constructor(p : tdef) : boolean;
  74. {# Returns true, if p points to a variant array }
  75. function is_variant_array(p : tdef) : boolean;
  76. {# Returns true, if p points to an array of const }
  77. function is_array_of_const(p : tdef) : boolean;
  78. {# Returns true, if p points any kind of special array
  79. That is if the array is an open array, a variant
  80. array, an array constants constructor, or an
  81. array of const.
  82. }
  83. function is_special_array(p : tdef) : boolean;
  84. {# Returns true if p is a char array def }
  85. function is_chararray(p : tdef) : boolean;
  86. {# Returns true if p is a wide char array def }
  87. function is_widechararray(p : tdef) : boolean;
  88. {*****************************************************************************
  89. String helper functions
  90. *****************************************************************************}
  91. {# Returns true if p points to an open string def }
  92. function is_open_string(p : tdef) : boolean;
  93. {# Returns true if p is an ansi string def }
  94. function is_ansistring(p : tdef) : boolean;
  95. {# Returns true if p is a long string def }
  96. function is_longstring(p : tdef) : boolean;
  97. {# returns true if p is a wide string def }
  98. function is_widestring(p : tdef) : boolean;
  99. {# Returns true if p is a short string def }
  100. function is_shortstring(p : tdef) : boolean;
  101. {# Returns true if p is a pchar def }
  102. function is_pchar(p : tdef) : boolean;
  103. {# Returns true if p is a pwidechar def }
  104. function is_pwidechar(p : tdef) : boolean;
  105. {# Returns true if p is a voidpointer def }
  106. function is_voidpointer(p : tdef) : boolean;
  107. {# Returns true, if definition is float }
  108. function is_fpu(def : tdef) : boolean;
  109. {# Returns true if the return value can be put in accumulator }
  110. function ret_in_acc(def : tdef) : boolean;
  111. {# Returns true if uses a parameter as return value (???) }
  112. function ret_in_param(def : tdef) : boolean;
  113. {# Returns true, if def is a 64 bit integer type }
  114. function is_64bitint(def : tdef) : boolean;
  115. function push_high_param(def : tdef) : boolean;
  116. {# Returns true if a parameter is too large to copy and only the address is pushed
  117. }
  118. function push_addr_param(def : tdef) : boolean;
  119. {# Returns true, if def1 and def2 are semantically the same }
  120. function is_equal(def1,def2 : tdef) : boolean;
  121. {# Checks for type compatibility (subgroups of type)
  122. used for case statements... probably missing stuff
  123. to use on other types
  124. }
  125. function is_subequal(def1, def2: tdef): boolean;
  126. type
  127. tconverttype = (
  128. tc_equal,
  129. tc_not_possible,
  130. tc_string_2_string,
  131. tc_char_2_string,
  132. tc_char_2_chararray,
  133. tc_pchar_2_string,
  134. tc_cchar_2_pchar,
  135. tc_cstring_2_pchar,
  136. tc_ansistring_2_pchar,
  137. tc_string_2_chararray,
  138. tc_chararray_2_string,
  139. tc_array_2_pointer,
  140. tc_pointer_2_array,
  141. tc_int_2_int,
  142. tc_int_2_bool,
  143. tc_bool_2_bool,
  144. tc_bool_2_int,
  145. tc_real_2_real,
  146. tc_int_2_real,
  147. tc_proc_2_procvar,
  148. tc_arrayconstructor_2_set,
  149. tc_load_smallset,
  150. tc_cord_2_pointer,
  151. tc_intf_2_string,
  152. tc_intf_2_guid,
  153. tc_class_2_intf,
  154. tc_char_2_char,
  155. tc_normal_2_smallset,
  156. tc_dynarray_2_openarray
  157. );
  158. function assignment_overloaded(from_def,to_def : tdef) : tprocdef;
  159. { Returns:
  160. 0 - Not convertable
  161. 1 - Convertable
  162. 2 - Convertable, but not first choice }
  163. function isconvertable(def_from,def_to : tdef;
  164. var doconv : tconverttype;
  165. fromtreetype : tnodetype;
  166. explicit : boolean) : byte;
  167. { Same as is_equal, but with error message if failed }
  168. function CheckTypes(def1,def2 : tdef) : boolean;
  169. function equal_constsym(sym1,sym2:tconstsym):boolean;
  170. {# true, if two parameter lists are equal
  171. if acp is cp_none, all have to match exactly
  172. if acp is cp_value_equal_const call by value
  173. and call by const parameter are assumed as
  174. equal
  175. }
  176. { if acp is cp_all the var const or nothing are considered equal }
  177. type
  178. compare_type = ( cp_none, cp_value_equal_const, cp_all);
  179. function equal_paras(paralist1,paralist2 : tlinkedlist; acp : compare_type) : boolean;
  180. { True if a type can be allowed for another one
  181. in a func var }
  182. function convertable_paras(paralist1,paralist2 : tlinkedlist; acp : compare_type) : boolean;
  183. { True if a function can be assigned to a procvar }
  184. { changed first argument type to pabstractprocdef so that it can also be }
  185. { used to test compatibility between two pprocvardefs (JM) }
  186. function proc_to_procvar_equal(def1:tabstractprocdef;def2:tprocvardef;exact:boolean) : boolean;
  187. function get_proc_2_procvar_def(p:tprocsym;d:tprocvardef):tprocdef;
  188. {# If @var(l) isn't in the range of def a range check error (if not explicit) is generated and
  189. the value is placed within the range
  190. }
  191. procedure testrange(def : tdef;var l : tconstexprint;explicit:boolean);
  192. {# Returns the range of def, where @var(l) is the low-range and @var(h) is
  193. the high-range.
  194. }
  195. procedure getrange(def : tdef;var l : TConstExprInt;var h : TConstExprInt);
  196. { some type helper routines for MMX support }
  197. function is_mmx_able_array(p : tdef) : boolean;
  198. {# returns the mmx type }
  199. function mmx_type(p : tdef) : tmmxtype;
  200. {# returns true, if sym needs an entry in the proplist of a class rtti }
  201. function needs_prop_entry(sym : tsym) : boolean;
  202. implementation
  203. uses
  204. globtype,cpubase,tokens,verbose,
  205. symtable;
  206. function needs_prop_entry(sym : tsym) : boolean;
  207. begin
  208. needs_prop_entry:=(sp_published in tsym(sym).symoptions) and
  209. (sym.typ in [propertysym,varsym]);
  210. end;
  211. function equal_constsym(sym1,sym2:tconstsym):boolean;
  212. var
  213. p1,p2,pend : pchar;
  214. begin
  215. equal_constsym:=false;
  216. if sym1.consttyp<>sym2.consttyp then
  217. exit;
  218. case sym1.consttyp of
  219. constint,
  220. constbool,
  221. constchar,
  222. constord :
  223. equal_constsym:=(sym1.valueord=sym2.valueord);
  224. constpointer :
  225. equal_constsym:=(sym1.valueordptr=sym2.valueordptr);
  226. conststring,constresourcestring :
  227. begin
  228. if sym1.len=sym2.len then
  229. begin
  230. p1:=pchar(sym1.valueptr);
  231. p2:=pchar(sym2.valueptr);
  232. pend:=p1+sym1.len;
  233. while (p1<pend) do
  234. begin
  235. if p1^<>p2^ then
  236. break;
  237. inc(p1);
  238. inc(p2);
  239. end;
  240. if (p1=pend) then
  241. equal_constsym:=true;
  242. end;
  243. end;
  244. constreal :
  245. equal_constsym:=(pbestreal(sym1.valueptr)^=pbestreal(sym2.valueptr)^);
  246. constset :
  247. equal_constsym:=(pnormalset(sym1.valueptr)^=pnormalset(sym2.valueptr)^);
  248. constnil :
  249. equal_constsym:=true;
  250. end;
  251. end;
  252. { compare_type = ( cp_none, cp_value_equal_const, cp_all); }
  253. function equal_paras(paralist1,paralist2 : TLinkedList; acp : compare_type) : boolean;
  254. var
  255. def1,def2 : TParaItem;
  256. begin
  257. def1:=TParaItem(paralist1.first);
  258. def2:=TParaItem(paralist2.first);
  259. while (assigned(def1)) and (assigned(def2)) do
  260. begin
  261. case acp of
  262. cp_value_equal_const :
  263. begin
  264. if not(is_equal(def1.paratype.def,def2.paratype.def)) or
  265. ((def1.paratyp<>def2.paratyp) and
  266. ((def1.paratyp in [vs_var,vs_out]) or
  267. (def2.paratyp in [vs_var,vs_out])
  268. )
  269. ) then
  270. begin
  271. equal_paras:=false;
  272. exit;
  273. end;
  274. end;
  275. cp_all :
  276. begin
  277. if not(is_equal(def1.paratype.def,def2.paratype.def)) or
  278. (def1.paratyp<>def2.paratyp) then
  279. begin
  280. equal_paras:=false;
  281. exit;
  282. end;
  283. end;
  284. cp_none :
  285. begin
  286. if not(is_equal(def1.paratype.def,def2.paratype.def)) then
  287. begin
  288. equal_paras:=false;
  289. exit;
  290. end;
  291. { also check default value if both have it declared }
  292. if assigned(def1.defaultvalue) and
  293. assigned(def2.defaultvalue) then
  294. begin
  295. if not equal_constsym(tconstsym(def1.defaultvalue),tconstsym(def2.defaultvalue)) then
  296. begin
  297. equal_paras:=false;
  298. exit;
  299. end;
  300. end;
  301. end;
  302. end;
  303. def1:=TParaItem(def1.next);
  304. def2:=TParaItem(def2.next);
  305. end;
  306. if (def1=nil) and (def2=nil) then
  307. equal_paras:=true
  308. else
  309. equal_paras:=false;
  310. end;
  311. function convertable_paras(paralist1,paralist2 : TLinkedList;acp : compare_type) : boolean;
  312. var
  313. def1,def2 : TParaItem;
  314. doconv : tconverttype;
  315. begin
  316. def1:=TParaItem(paralist1.first);
  317. def2:=TParaItem(paralist2.first);
  318. while (assigned(def1)) and (assigned(def2)) do
  319. begin
  320. case acp of
  321. cp_value_equal_const :
  322. begin
  323. if (isconvertable(def1.paratype.def,def2.paratype.def,doconv,callparan,false)=0) or
  324. ((def1.paratyp<>def2.paratyp) and
  325. ((def1.paratyp in [vs_out,vs_var]) or
  326. (def2.paratyp in [vs_out,vs_var])
  327. )
  328. ) then
  329. begin
  330. convertable_paras:=false;
  331. exit;
  332. end;
  333. end;
  334. cp_all :
  335. begin
  336. if (isconvertable(def1.paratype.def,def2.paratype.def,doconv,callparan,false)=0) or
  337. (def1.paratyp<>def2.paratyp) then
  338. begin
  339. convertable_paras:=false;
  340. exit;
  341. end;
  342. end;
  343. cp_none :
  344. begin
  345. if (isconvertable(def1.paratype.def,def2.paratype.def,doconv,callparan,false)=0) then
  346. begin
  347. convertable_paras:=false;
  348. exit;
  349. end;
  350. end;
  351. end;
  352. def1:=TParaItem(def1.next);
  353. def2:=TParaItem(def2.next);
  354. end;
  355. if (def1=nil) and (def2=nil) then
  356. convertable_paras:=true
  357. else
  358. convertable_paras:=false;
  359. end;
  360. { true if a function can be assigned to a procvar }
  361. { changed first argument type to pabstractprocdef so that it can also be }
  362. { used to test compatibility between two pprocvardefs (JM) }
  363. function proc_to_procvar_equal(def1:tabstractprocdef;def2:tprocvardef;exact:boolean) : boolean;
  364. const
  365. po_comp = po_compatibility_options-[po_methodpointer,po_classmethod];
  366. var
  367. ismethod : boolean;
  368. begin
  369. proc_to_procvar_equal:=false;
  370. if not(assigned(def1)) or not(assigned(def2)) then
  371. exit;
  372. { check for method pointer }
  373. if def1.deftype=procvardef then
  374. begin
  375. ismethod:=(po_methodpointer in def1.procoptions);
  376. end
  377. else
  378. begin
  379. ismethod:=assigned(def1.owner) and
  380. (def1.owner.symtabletype=objectsymtable);
  381. end;
  382. if (ismethod and not (po_methodpointer in def2.procoptions)) or
  383. (not(ismethod) and (po_methodpointer in def2.procoptions)) then
  384. begin
  385. Message(type_e_no_method_and_procedure_not_compatible);
  386. exit;
  387. end;
  388. { check return value and para's and options, methodpointer is already checked
  389. parameters may also be convertable }
  390. if is_equal(def1.rettype.def,def2.rettype.def) and
  391. (equal_paras(def1.para,def2.para,cp_all) or
  392. ((not exact) and convertable_paras(def1.para,def2.para,cp_all))) and
  393. ((po_comp * def1.procoptions)= (po_comp * def2.procoptions)) then
  394. proc_to_procvar_equal:=true
  395. else
  396. proc_to_procvar_equal:=false;
  397. end;
  398. function get_proc_2_procvar_def(p:tprocsym;d:tprocvardef):tprocdef;
  399. var
  400. matchprocdef : tprocdef;
  401. pd : pprocdeflist;
  402. begin
  403. { This function will return the pprocdef of pprocsym that
  404. is the best match for procvardef. When there are multiple
  405. matches it returns nil }
  406. { exact match }
  407. matchprocdef:=nil;
  408. pd:=p.defs;
  409. while assigned(pd) do
  410. begin
  411. if proc_to_procvar_equal(pd^.def,d,true) then
  412. begin
  413. { already found a match ? Then stop and return nil }
  414. if assigned(matchprocdef) then
  415. begin
  416. matchprocdef:=nil;
  417. break;
  418. end;
  419. matchprocdef:=pd^.def;
  420. end;
  421. pd:=pd^.next;
  422. end;
  423. { convertable match, if no exact match was found }
  424. if not assigned(matchprocdef) and
  425. not assigned(pd) then
  426. begin
  427. pd:=p.defs;
  428. while assigned(pd) do
  429. begin
  430. if proc_to_procvar_equal(pd^.def,d,false) then
  431. begin
  432. { already found a match ? Then stop and return nil }
  433. if assigned(matchprocdef) then
  434. begin
  435. matchprocdef:=nil;
  436. break;
  437. end;
  438. matchprocdef:=pd^.def;
  439. end;
  440. pd:=pd^.next;
  441. end;
  442. end;
  443. get_proc_2_procvar_def:=matchprocdef;
  444. end;
  445. { returns true, if def uses FPU }
  446. function is_fpu(def : tdef) : boolean;
  447. begin
  448. is_fpu:=(def.deftype=floatdef);
  449. end;
  450. function range_to_basetype(low,high:TConstExprInt):tbasetype;
  451. begin
  452. { generate a unsigned range if high<0 and low>=0 }
  453. if (low>=0) and (high<0) then
  454. range_to_basetype:=u32bit
  455. else if (low>=0) and (high<=255) then
  456. range_to_basetype:=u8bit
  457. else if (low>=-128) and (high<=127) then
  458. range_to_basetype:=s8bit
  459. else if (low>=0) and (high<=65536) then
  460. range_to_basetype:=u16bit
  461. else if (low>=-32768) and (high<=32767) then
  462. range_to_basetype:=s16bit
  463. else
  464. range_to_basetype:=s32bit;
  465. end;
  466. { true if p is an ordinal }
  467. function is_ordinal(def : tdef) : boolean;
  468. var
  469. dt : tbasetype;
  470. begin
  471. case def.deftype of
  472. orddef :
  473. begin
  474. dt:=torddef(def).typ;
  475. is_ordinal:=dt in [uchar,uwidechar,
  476. u8bit,u16bit,u32bit,u64bit,
  477. s8bit,s16bit,s32bit,s64bit,
  478. bool8bit,bool16bit,bool32bit];
  479. end;
  480. enumdef :
  481. is_ordinal:=true;
  482. else
  483. is_ordinal:=false;
  484. end;
  485. end;
  486. { returns the min. value of the type }
  487. function get_min_value(def : tdef) : TConstExprInt;
  488. begin
  489. case def.deftype of
  490. orddef:
  491. get_min_value:=torddef(def).low;
  492. enumdef:
  493. get_min_value:=tenumdef(def).min;
  494. else
  495. get_min_value:=0;
  496. end;
  497. end;
  498. { true if p is an integer }
  499. function is_integer(def : tdef) : boolean;
  500. begin
  501. is_integer:=(def.deftype=orddef) and
  502. (torddef(def).typ in [u8bit,u16bit,u32bit,u64bit,
  503. s8bit,s16bit,s32bit,s64bit]);
  504. end;
  505. { true if p is a boolean }
  506. function is_boolean(def : tdef) : boolean;
  507. begin
  508. is_boolean:=(def.deftype=orddef) and
  509. (torddef(def).typ in [bool8bit,bool16bit,bool32bit]);
  510. end;
  511. { true if p is a void }
  512. function is_void(def : tdef) : boolean;
  513. begin
  514. is_void:=(def.deftype=orddef) and
  515. (torddef(def).typ=uvoid);
  516. end;
  517. { true if p is a char }
  518. function is_char(def : tdef) : boolean;
  519. begin
  520. is_char:=(def.deftype=orddef) and
  521. (torddef(def).typ=uchar);
  522. end;
  523. { true if p is a wchar }
  524. function is_widechar(def : tdef) : boolean;
  525. begin
  526. is_widechar:=(def.deftype=orddef) and
  527. (torddef(def).typ=uwidechar);
  528. end;
  529. { true if p is signed (integer) }
  530. function is_signed(def : tdef) : boolean;
  531. var
  532. dt : tbasetype;
  533. begin
  534. case def.deftype of
  535. orddef :
  536. begin
  537. dt:=torddef(def).typ;
  538. is_signed:=(dt in [s8bit,s16bit,s32bit,s64bit]);
  539. end;
  540. enumdef :
  541. is_signed:=tenumdef(def).min < 0;
  542. arraydef :
  543. is_signed:=is_signed(tarraydef(def).rangetype.def);
  544. else
  545. is_signed:=false;
  546. end;
  547. end;
  548. function is_in_limit(def_from,def_to : tdef) : boolean;
  549. var
  550. fromqword, toqword: boolean;
  551. begin
  552. if (def_from.deftype <> orddef) or
  553. (def_to.deftype <> orddef) then
  554. begin
  555. is_in_limit := false;
  556. exit;
  557. end;
  558. fromqword := torddef(def_from).typ = u64bit;
  559. toqword := torddef(def_to).typ = u64bit;
  560. is_in_limit:=((not(fromqword xor toqword) and
  561. (torddef(def_from).low>=torddef(def_to).low) and
  562. (torddef(def_from).high<=torddef(def_to).high)) or
  563. (toqword and not is_signed(def_from)));
  564. end;
  565. { true, if p points to an open array def }
  566. function is_open_string(p : tdef) : boolean;
  567. begin
  568. is_open_string:=(p.deftype=stringdef) and
  569. (tstringdef(p).string_typ=st_shortstring) and
  570. (tstringdef(p).len=0);
  571. end;
  572. { true, if p points to a zero based array def }
  573. function is_zero_based_array(p : tdef) : boolean;
  574. begin
  575. is_zero_based_array:=(p.deftype=arraydef) and
  576. (tarraydef(p).lowrange=0) and
  577. not(is_special_array(p));
  578. end;
  579. { true if p points to a dynamic array def }
  580. function is_dynamic_array(p : tdef) : boolean;
  581. begin
  582. is_dynamic_array:=(p.deftype=arraydef) and
  583. tarraydef(p).IsDynamicArray;
  584. end;
  585. { true, if p points to an open array def }
  586. function is_open_array(p : tdef) : boolean;
  587. begin
  588. { check for s32bittype is needed, because for u32bit the high
  589. range is also -1 ! (PFV) }
  590. is_open_array:=(p.deftype=arraydef) and
  591. (tarraydef(p).rangetype.def=s32bittype.def) and
  592. (tarraydef(p).lowrange=0) and
  593. (tarraydef(p).highrange=-1) and
  594. not(tarraydef(p).IsConstructor) and
  595. not(tarraydef(p).IsVariant) and
  596. not(tarraydef(p).IsArrayOfConst) and
  597. not(tarraydef(p).IsDynamicArray);
  598. end;
  599. { true, if p points to an array of const def }
  600. function is_array_constructor(p : tdef) : boolean;
  601. begin
  602. is_array_constructor:=(p.deftype=arraydef) and
  603. (tarraydef(p).IsConstructor);
  604. end;
  605. { true, if p points to a variant array }
  606. function is_variant_array(p : tdef) : boolean;
  607. begin
  608. is_variant_array:=(p.deftype=arraydef) and
  609. (tarraydef(p).IsVariant);
  610. end;
  611. { true, if p points to an array of const }
  612. function is_array_of_const(p : tdef) : boolean;
  613. begin
  614. is_array_of_const:=(p.deftype=arraydef) and
  615. (tarraydef(p).IsArrayOfConst);
  616. end;
  617. { true, if p points to a special array }
  618. function is_special_array(p : tdef) : boolean;
  619. begin
  620. is_special_array:=(p.deftype=arraydef) and
  621. ((tarraydef(p).IsVariant) or
  622. (tarraydef(p).IsArrayOfConst) or
  623. (tarraydef(p).IsConstructor) or
  624. is_open_array(p)
  625. );
  626. end;
  627. { true if p is an ansi string def }
  628. function is_ansistring(p : tdef) : boolean;
  629. begin
  630. is_ansistring:=(p.deftype=stringdef) and
  631. (tstringdef(p).string_typ=st_ansistring);
  632. end;
  633. { true if p is an long string def }
  634. function is_longstring(p : tdef) : boolean;
  635. begin
  636. is_longstring:=(p.deftype=stringdef) and
  637. (tstringdef(p).string_typ=st_longstring);
  638. end;
  639. { true if p is an wide string def }
  640. function is_widestring(p : tdef) : boolean;
  641. begin
  642. is_widestring:=(p.deftype=stringdef) and
  643. (tstringdef(p).string_typ=st_widestring);
  644. end;
  645. { true if p is an short string def }
  646. function is_shortstring(p : tdef) : boolean;
  647. begin
  648. is_shortstring:=(p.deftype=stringdef) and
  649. (tstringdef(p).string_typ=st_shortstring);
  650. end;
  651. { true if p is a char array def }
  652. function is_chararray(p : tdef) : boolean;
  653. begin
  654. is_chararray:=(p.deftype=arraydef) and
  655. is_equal(tarraydef(p).elementtype.def,cchartype.def) and
  656. not(is_special_array(p));
  657. end;
  658. { true if p is a widechar array def }
  659. function is_widechararray(p : tdef) : boolean;
  660. begin
  661. is_widechararray:=(p.deftype=arraydef) and
  662. is_equal(tarraydef(p).elementtype.def,cwidechartype.def) and
  663. not(is_special_array(p));
  664. end;
  665. { true if p is a pchar def }
  666. function is_pchar(p : tdef) : boolean;
  667. begin
  668. is_pchar:=(p.deftype=pointerdef) and
  669. (is_equal(tpointerdef(p).pointertype.def,cchartype.def) or
  670. (is_zero_based_array(tpointerdef(p).pointertype.def) and
  671. is_chararray(tpointerdef(p).pointertype.def)));
  672. end;
  673. { true if p is a pchar def }
  674. function is_pwidechar(p : tdef) : boolean;
  675. begin
  676. is_pwidechar:=(p.deftype=pointerdef) and
  677. (is_equal(tpointerdef(p).pointertype.def,cwidechartype.def) or
  678. (is_zero_based_array(tpointerdef(p).pointertype.def) and
  679. is_widechararray(tpointerdef(p).pointertype.def)));
  680. end;
  681. { true if p is a voidpointer def }
  682. function is_voidpointer(p : tdef) : boolean;
  683. begin
  684. is_voidpointer:=(p.deftype=pointerdef) and
  685. (tpointerdef(p).pointertype.def.deftype=orddef) and
  686. (torddef(tpointerdef(p).pointertype.def).typ=uvoid);
  687. end;
  688. { true if p is a smallset def }
  689. function is_smallset(p : tdef) : boolean;
  690. begin
  691. is_smallset:=(p.deftype=setdef) and
  692. (tsetdef(p).settype=smallset);
  693. end;
  694. { true if the return value is in accumulator (EAX for i386), D0 for 68k }
  695. function ret_in_acc(def : tdef) : boolean;
  696. begin
  697. ret_in_acc:=(def.deftype in [orddef,pointerdef,enumdef,classrefdef]) or
  698. ((def.deftype=stringdef) and (tstringdef(def).string_typ in [st_ansistring,st_widestring])) or
  699. ((def.deftype=procvardef) and not(po_methodpointer in tprocvardef(def).procoptions)) or
  700. ((def.deftype=objectdef) and not is_object(def)) or
  701. ((def.deftype=setdef) and (tsetdef(def).settype=smallset));
  702. end;
  703. { true, if def is a 64 bit int type }
  704. function is_64bitint(def : tdef) : boolean;
  705. begin
  706. is_64bitint:=(def.deftype=orddef) and (torddef(def).typ in [u64bit,s64bit])
  707. end;
  708. { true if uses a parameter as return value }
  709. function ret_in_param(def : tdef) : boolean;
  710. begin
  711. ret_in_param:=(def.deftype in [arraydef,recorddef]) or
  712. ((def.deftype=stringdef) and (tstringdef(def).string_typ in [st_shortstring,st_longstring])) or
  713. ((def.deftype=procvardef) and (po_methodpointer in tprocvardef(def).procoptions)) or
  714. ((def.deftype=objectdef) and is_object(def)) or
  715. (def.deftype=variantdef) or
  716. ((def.deftype=setdef) and (tsetdef(def).settype<>smallset));
  717. end;
  718. function push_high_param(def : tdef) : boolean;
  719. begin
  720. push_high_param:=is_open_array(def) or
  721. is_open_string(def) or
  722. is_array_of_const(def);
  723. end;
  724. { true if a parameter is too large to copy and only the address is pushed }
  725. function push_addr_param(def : tdef) : boolean;
  726. begin
  727. push_addr_param:=false;
  728. if never_copy_const_param then
  729. push_addr_param:=true
  730. else
  731. begin
  732. case def.deftype of
  733. variantdef,
  734. formaldef :
  735. push_addr_param:=true;
  736. recorddef :
  737. push_addr_param:=(def.size>pointer_size);
  738. arraydef :
  739. push_addr_param:=((tarraydef(def).highrange>=tarraydef(def).lowrange) and (def.size>pointer_size)) or
  740. is_open_array(def) or
  741. is_array_of_const(def) or
  742. is_array_constructor(def);
  743. objectdef :
  744. push_addr_param:=is_object(def);
  745. stringdef :
  746. push_addr_param:=tstringdef(def).string_typ in [st_shortstring,st_longstring];
  747. procvardef :
  748. push_addr_param:=(po_methodpointer in tprocvardef(def).procoptions);
  749. setdef :
  750. push_addr_param:=(tsetdef(def).settype<>smallset);
  751. end;
  752. end;
  753. end;
  754. { if l isn't in the range of def a range check error (if not explicit) is generated and
  755. the value is placed within the range }
  756. procedure testrange(def : tdef;var l : tconstexprint;explicit:boolean);
  757. var
  758. lv,hv: TConstExprInt;
  759. error: boolean;
  760. begin
  761. error := false;
  762. { for 64 bit types we need only to check if it is less than }
  763. { zero, if def is a qword node }
  764. if is_64bitint(def) then
  765. begin
  766. if (l<0) and (torddef(def).typ=u64bit) then
  767. begin
  768. { don't zero the result, because it may come from hex notation
  769. like $ffffffffffffffff! (JM)
  770. l:=0; }
  771. if not explicit then
  772. begin
  773. if (cs_check_range in aktlocalswitches) then
  774. Message(parser_e_range_check_error)
  775. else
  776. Message(parser_w_range_check_error);
  777. end;
  778. error := true;
  779. end;
  780. end
  781. else
  782. begin
  783. getrange(def,lv,hv);
  784. if (def.deftype=orddef) and
  785. (torddef(def).typ=u32bit) then
  786. begin
  787. if (l < cardinal(lv)) or
  788. (l > cardinal(hv)) then
  789. begin
  790. if not explicit then
  791. begin
  792. if (cs_check_range in aktlocalswitches) then
  793. Message(parser_e_range_check_error)
  794. else
  795. Message(parser_w_range_check_error);
  796. end;
  797. error := true;
  798. end;
  799. end
  800. else if (l<lv) or (l>hv) then
  801. begin
  802. if not explicit then
  803. begin
  804. if ((def.deftype=enumdef) and
  805. { delphi allows range check errors in
  806. enumeration type casts FK }
  807. not(m_delphi in aktmodeswitches)) or
  808. (cs_check_range in aktlocalswitches) then
  809. Message(parser_e_range_check_error)
  810. else
  811. Message(parser_w_range_check_error);
  812. end;
  813. error := true;
  814. end;
  815. end;
  816. if error then
  817. begin
  818. { Fix the value to fit in the allocated space for this type of variable }
  819. case def.size of
  820. 1: l := l and $ff;
  821. 2: l := l and $ffff;
  822. { work around sign extension bug (to be fixed) (JM) }
  823. 4: l := l and (int64($fffffff) shl 4 + $f);
  824. end;
  825. { do sign extension if necessary (JM) }
  826. if is_signed(def) then
  827. begin
  828. case def.size of
  829. 1: l := shortint(l);
  830. 2: l := smallint(l);
  831. 4: l := longint(l);
  832. end;
  833. end;
  834. end;
  835. end;
  836. { return the range from def in l and h }
  837. procedure getrange(def : tdef;var l : TConstExprInt;var h : TConstExprInt);
  838. begin
  839. case def.deftype of
  840. orddef :
  841. begin
  842. l:=torddef(def).low;
  843. h:=torddef(def).high;
  844. end;
  845. enumdef :
  846. begin
  847. l:=tenumdef(def).min;
  848. h:=tenumdef(def).max;
  849. end;
  850. arraydef :
  851. begin
  852. l:=tarraydef(def).lowrange;
  853. h:=tarraydef(def).highrange;
  854. end;
  855. else
  856. internalerror(987);
  857. end;
  858. end;
  859. function mmx_type(p : tdef) : tmmxtype;
  860. begin
  861. mmx_type:=mmxno;
  862. if is_mmx_able_array(p) then
  863. begin
  864. if tarraydef(p).elementtype.def.deftype=floatdef then
  865. case tfloatdef(tarraydef(p).elementtype.def).typ of
  866. s32real:
  867. mmx_type:=mmxsingle;
  868. end
  869. else
  870. case torddef(tarraydef(p).elementtype.def).typ of
  871. u8bit:
  872. mmx_type:=mmxu8bit;
  873. s8bit:
  874. mmx_type:=mmxs8bit;
  875. u16bit:
  876. mmx_type:=mmxu16bit;
  877. s16bit:
  878. mmx_type:=mmxs16bit;
  879. u32bit:
  880. mmx_type:=mmxu32bit;
  881. s32bit:
  882. mmx_type:=mmxs32bit;
  883. end;
  884. end;
  885. end;
  886. function is_mmx_able_array(p : tdef) : boolean;
  887. begin
  888. {$ifdef SUPPORT_MMX}
  889. if (cs_mmx_saturation in aktlocalswitches) then
  890. begin
  891. is_mmx_able_array:=(p.deftype=arraydef) and
  892. not(is_special_array(p)) and
  893. (
  894. (
  895. (tarraydef(p).elementtype.def.deftype=orddef) and
  896. (
  897. (
  898. (tarraydef(p).lowrange=0) and
  899. (tarraydef(p).highrange=1) and
  900. (torddef(tarraydef(p).elementtype.def).typ in [u32bit,s32bit])
  901. )
  902. or
  903. (
  904. (tarraydef(p).lowrange=0) and
  905. (tarraydef(p).highrange=3) and
  906. (torddef(tarraydef(p).elementtype.def).typ in [u16bit,s16bit])
  907. )
  908. )
  909. )
  910. or
  911. (
  912. (
  913. (tarraydef(p).elementtype.def.deftype=floatdef) and
  914. (
  915. (tarraydef(p).lowrange=0) and
  916. (tarraydef(p).highrange=1) and
  917. (tfloatdef(tarraydef(p).elementtype.def).typ=s32real)
  918. )
  919. )
  920. )
  921. );
  922. end
  923. else
  924. begin
  925. is_mmx_able_array:=(p.deftype=arraydef) and
  926. (
  927. (
  928. (tarraydef(p).elementtype.def.deftype=orddef) and
  929. (
  930. (
  931. (tarraydef(p).lowrange=0) and
  932. (tarraydef(p).highrange=1) and
  933. (torddef(tarraydef(p).elementtype.def).typ in [u32bit,s32bit])
  934. )
  935. or
  936. (
  937. (tarraydef(p).lowrange=0) and
  938. (tarraydef(p).highrange=3) and
  939. (torddef(tarraydef(p).elementtype.def).typ in [u16bit,s16bit])
  940. )
  941. or
  942. (
  943. (tarraydef(p).lowrange=0) and
  944. (tarraydef(p).highrange=7) and
  945. (torddef(tarraydef(p).elementtype.def).typ in [u8bit,s8bit])
  946. )
  947. )
  948. )
  949. or
  950. (
  951. (tarraydef(p).elementtype.def.deftype=floatdef) and
  952. (
  953. (tarraydef(p).lowrange=0) and
  954. (tarraydef(p).highrange=1) and
  955. (tfloatdef(tarraydef(p).elementtype.def).typ=s32real)
  956. )
  957. )
  958. );
  959. end;
  960. {$else SUPPORT_MMX}
  961. is_mmx_able_array:=false;
  962. {$endif SUPPORT_MMX}
  963. end;
  964. function is_equal(def1,def2 : tdef) : boolean;
  965. var
  966. b : boolean;
  967. hd : tdef;
  968. begin
  969. { both types must exists }
  970. if not (assigned(def1) and assigned(def2)) then
  971. begin
  972. is_equal:=false;
  973. exit;
  974. end;
  975. { be sure, that if there is a stringdef, that this is def1 }
  976. if def2.deftype=stringdef then
  977. begin
  978. hd:=def1;
  979. def1:=def2;
  980. def2:=hd;
  981. end;
  982. b:=false;
  983. { both point to the same definition ? }
  984. if def1=def2 then
  985. b:=true
  986. else
  987. { pointer with an equal definition are equal }
  988. if (def1.deftype=pointerdef) and (def2.deftype=pointerdef) then
  989. begin
  990. { check if both are farpointer }
  991. if (tpointerdef(def1).is_far=tpointerdef(def2).is_far) then
  992. begin
  993. { here a problem detected in tabsolutesym }
  994. { the types can be forward type !! }
  995. if assigned(def1.typesym) and (tpointerdef(def1).pointertype.def.deftype=forwarddef) then
  996. b:=(def1.typesym=def2.typesym)
  997. else
  998. b:=tpointerdef(def1).pointertype.def=tpointerdef(def2).pointertype.def;
  999. end
  1000. else
  1001. b:=false;
  1002. end
  1003. else
  1004. { ordinals are equal only when the ordinal type is equal }
  1005. if (def1.deftype=orddef) and (def2.deftype=orddef) then
  1006. begin
  1007. case torddef(def1).typ of
  1008. u8bit,u16bit,u32bit,
  1009. s8bit,s16bit,s32bit:
  1010. b:=((torddef(def1).typ=torddef(def2).typ) and
  1011. (torddef(def1).low=torddef(def2).low) and
  1012. (torddef(def1).high=torddef(def2).high));
  1013. uvoid,uchar,uwidechar,
  1014. bool8bit,bool16bit,bool32bit:
  1015. b:=(torddef(def1).typ=torddef(def2).typ);
  1016. end;
  1017. end
  1018. else
  1019. if (def1.deftype=floatdef) and (def2.deftype=floatdef) then
  1020. b:=tfloatdef(def1).typ=tfloatdef(def2).typ
  1021. else
  1022. { strings with the same length are equal }
  1023. if (def1.deftype=stringdef) and (def2.deftype=stringdef) and
  1024. (tstringdef(def1).string_typ=tstringdef(def2).string_typ) then
  1025. begin
  1026. b:=not(is_shortstring(def1)) or
  1027. (tstringdef(def1).len=tstringdef(def2).len);
  1028. end
  1029. else
  1030. if (def1.deftype=formaldef) and (def2.deftype=formaldef) then
  1031. b:=true
  1032. { file types with the same file element type are equal }
  1033. { this is a problem for assign !! }
  1034. { changed to allow if one is untyped }
  1035. { all typed files are equal to the special }
  1036. { typed file that has voiddef as elemnt type }
  1037. { but must NOT match for text file !!! }
  1038. else
  1039. if (def1.deftype=filedef) and (def2.deftype=filedef) then
  1040. b:=(tfiledef(def1).filetyp=tfiledef(def2).filetyp) and
  1041. ((
  1042. ((tfiledef(def1).typedfiletype.def=nil) and
  1043. (tfiledef(def2).typedfiletype.def=nil)) or
  1044. (
  1045. (tfiledef(def1).typedfiletype.def<>nil) and
  1046. (tfiledef(def2).typedfiletype.def<>nil) and
  1047. is_equal(tfiledef(def1).typedfiletype.def,tfiledef(def2).typedfiletype.def)
  1048. ) or
  1049. ( (tfiledef(def1).typedfiletype.def=tdef(voidtype.def)) or
  1050. (tfiledef(def2).typedfiletype.def=tdef(voidtype.def))
  1051. )))
  1052. { sets with the same element base type are equal }
  1053. else
  1054. if (def1.deftype=setdef) and (def2.deftype=setdef) then
  1055. begin
  1056. if assigned(tsetdef(def1).elementtype.def) and
  1057. assigned(tsetdef(def2).elementtype.def) then
  1058. b:=is_subequal(tsetdef(def1).elementtype.def,tsetdef(def2).elementtype.def)
  1059. else
  1060. { empty set is compatible with everything }
  1061. b:=true;
  1062. end
  1063. else
  1064. if (def1.deftype=procvardef) and (def2.deftype=procvardef) then
  1065. begin
  1066. { poassembler isn't important for compatibility }
  1067. { if a method is assigned to a methodpointer }
  1068. { is checked before }
  1069. b:=(tprocvardef(def1).proctypeoption=tprocvardef(def2).proctypeoption) and
  1070. (tprocvardef(def1).proccalloption=tprocvardef(def2).proccalloption) and
  1071. ((tprocvardef(def1).procoptions * po_compatibility_options)=
  1072. (tprocvardef(def2).procoptions * po_compatibility_options)) and
  1073. is_equal(tprocvardef(def1).rettype.def,tprocvardef(def2).rettype.def) and
  1074. equal_paras(tprocvardef(def1).para,tprocvardef(def2).para,cp_all);
  1075. end
  1076. else
  1077. if (def1.deftype=arraydef) and (def2.deftype=arraydef) then
  1078. begin
  1079. if is_dynamic_array(def1) and is_dynamic_array(def2) then
  1080. b:=is_equal(tarraydef(def1).elementtype.def,tarraydef(def2).elementtype.def)
  1081. else
  1082. if is_array_of_const(def1) or is_array_of_const(def2) then
  1083. begin
  1084. b:=(is_array_of_const(def1) and is_array_of_const(def2)) or
  1085. (is_array_of_const(def1) and is_array_constructor(def2)) or
  1086. (is_array_of_const(def2) and is_array_constructor(def1));
  1087. end
  1088. else
  1089. if (is_dynamic_array(def1) or is_dynamic_array(def2)) then
  1090. begin
  1091. b := is_dynamic_array(def1) and is_dynamic_array(def2) and
  1092. is_equal(tarraydef(def1).elementtype.def,tarraydef(def2).elementtype.def);
  1093. end
  1094. else
  1095. if is_open_array(def1) or is_open_array(def2) then
  1096. begin
  1097. b:=is_equal(tarraydef(def1).elementtype.def,tarraydef(def2).elementtype.def);
  1098. end
  1099. else
  1100. begin
  1101. b:=not(m_tp7 in aktmodeswitches) and
  1102. not(m_delphi in aktmodeswitches) and
  1103. (tarraydef(def1).lowrange=tarraydef(def2).lowrange) and
  1104. (tarraydef(def1).highrange=tarraydef(def2).highrange) and
  1105. is_equal(tarraydef(def1).elementtype.def,tarraydef(def2).elementtype.def) and
  1106. is_equal(tarraydef(def1).rangetype.def,tarraydef(def2).rangetype.def);
  1107. end;
  1108. end
  1109. else
  1110. if (def1.deftype=classrefdef) and (def2.deftype=classrefdef) then
  1111. begin
  1112. { similar to pointerdef: }
  1113. if assigned(def1.typesym) and (tclassrefdef(def1).pointertype.def.deftype=forwarddef) then
  1114. b:=(def1.typesym=def2.typesym)
  1115. else
  1116. b:=is_equal(tclassrefdef(def1).pointertype.def,tclassrefdef(def2).pointertype.def);
  1117. end;
  1118. is_equal:=b;
  1119. end;
  1120. function is_subequal(def1, def2: tdef): boolean;
  1121. var
  1122. basedef1,basedef2 : tenumdef;
  1123. Begin
  1124. is_subequal := false;
  1125. if assigned(def1) and assigned(def2) then
  1126. Begin
  1127. if (def1.deftype = orddef) and (def2.deftype = orddef) then
  1128. Begin
  1129. { see p.47 of Turbo Pascal 7.01 manual for the separation of types }
  1130. { range checking for case statements is done with testrange }
  1131. case torddef(def1).typ of
  1132. u8bit,u16bit,u32bit,
  1133. s8bit,s16bit,s32bit,s64bit,u64bit :
  1134. is_subequal:=(torddef(def2).typ in [s64bit,u64bit,s32bit,u32bit,u8bit,s8bit,s16bit,u16bit]);
  1135. bool8bit,bool16bit,bool32bit :
  1136. is_subequal:=(torddef(def2).typ in [bool8bit,bool16bit,bool32bit]);
  1137. uchar :
  1138. is_subequal:=(torddef(def2).typ=uchar);
  1139. uwidechar :
  1140. is_subequal:=(torddef(def2).typ=uwidechar);
  1141. end;
  1142. end
  1143. else
  1144. Begin
  1145. { I assume that both enumerations are equal when the first }
  1146. { pointers are equal. }
  1147. { I changed this to assume that the enums are equal }
  1148. { if the basedefs are equal (FK) }
  1149. if (def1.deftype=enumdef) and (def2.deftype=enumdef) then
  1150. Begin
  1151. { get both basedefs }
  1152. basedef1:=tenumdef(def1);
  1153. while assigned(basedef1.basedef) do
  1154. basedef1:=basedef1.basedef;
  1155. basedef2:=tenumdef(def2);
  1156. while assigned(basedef2.basedef) do
  1157. basedef2:=basedef2.basedef;
  1158. is_subequal:=basedef1=basedef2;
  1159. {
  1160. if tenumdef(def1).firstenum = tenumdef(def2).firstenum then
  1161. is_subequal := TRUE;
  1162. }
  1163. end;
  1164. end;
  1165. end; { endif assigned ... }
  1166. end;
  1167. function assignment_overloaded(from_def,to_def : tdef) : tprocdef;
  1168. var
  1169. passprocs : pprocdeflist;
  1170. convtyp : tconverttype;
  1171. begin
  1172. assignment_overloaded:=nil;
  1173. if not assigned(overloaded_operators[_ASSIGNMENT]) then
  1174. exit;
  1175. { look for an exact match first }
  1176. passprocs:=overloaded_operators[_ASSIGNMENT].defs;
  1177. while assigned(passprocs) do
  1178. begin
  1179. if is_equal(passprocs^.def.rettype.def,to_def) and
  1180. (TParaItem(passprocs^.def.Para.first).paratype.def=from_def) then
  1181. begin
  1182. assignment_overloaded:=passprocs^.def;
  1183. exit;
  1184. end;
  1185. passprocs:=passprocs^.next;
  1186. end;
  1187. { .... then look for an equal match }
  1188. passprocs:=overloaded_operators[_ASSIGNMENT].defs;
  1189. while assigned(passprocs) do
  1190. begin
  1191. if is_equal(passprocs^.def.rettype.def,to_def) and
  1192. is_equal(TParaItem(passprocs^.def.Para.first).paratype.def,from_def) then
  1193. begin
  1194. assignment_overloaded:=passprocs^.def;
  1195. exit;
  1196. end;
  1197. passprocs:=passprocs^.next;
  1198. end;
  1199. { .... then for convert level 1 }
  1200. passprocs:=overloaded_operators[_ASSIGNMENT].defs;
  1201. while assigned(passprocs) do
  1202. begin
  1203. if is_equal(passprocs^.def.rettype.def,to_def) and
  1204. (isconvertable(from_def,TParaItem(passprocs^.def.Para.first).paratype.def,convtyp,ordconstn,false)=1) then
  1205. begin
  1206. assignment_overloaded:=passprocs^.def;
  1207. exit;
  1208. end;
  1209. passprocs:=passprocs^.next;
  1210. end;
  1211. end;
  1212. { Returns:
  1213. 0 - Not convertable
  1214. 1 - Convertable
  1215. 2 - Convertable, but not first choice }
  1216. function isconvertable(def_from,def_to : tdef;
  1217. var doconv : tconverttype;
  1218. fromtreetype : tnodetype;
  1219. explicit : boolean) : byte;
  1220. { Tbasetype:
  1221. uvoid,
  1222. u8bit,u16bit,u32bit,u64bit,
  1223. s8bit,s16bit,s32bit,s64bit,
  1224. bool8bit,bool16bit,bool32bit,
  1225. uchar,uwidechar }
  1226. type
  1227. tbasedef=(bvoid,bchar,bint,bbool);
  1228. const
  1229. basedeftbl:array[tbasetype] of tbasedef =
  1230. (bvoid,
  1231. bint,bint,bint,bint,
  1232. bint,bint,bint,bint,
  1233. bbool,bbool,bbool,
  1234. bchar,bchar);
  1235. basedefconverts : array[tbasedef,tbasedef] of tconverttype =
  1236. ((tc_not_possible,tc_not_possible,tc_not_possible,tc_not_possible),
  1237. (tc_not_possible,tc_char_2_char,tc_not_possible,tc_not_possible),
  1238. (tc_not_possible,tc_not_possible,tc_int_2_int,tc_int_2_bool),
  1239. (tc_not_possible,tc_not_possible,tc_bool_2_int,tc_bool_2_bool));
  1240. var
  1241. b : byte;
  1242. hd1,hd2 : tdef;
  1243. hct : tconverttype;
  1244. begin
  1245. { safety check }
  1246. if not(assigned(def_from) and assigned(def_to)) then
  1247. begin
  1248. isconvertable:=0;
  1249. exit;
  1250. end;
  1251. { tp7 procvar def support, in tp7 a procvar is always called, if the
  1252. procvar is passed explicit a addrn would be there }
  1253. if (m_tp_procvar in aktmodeswitches) and
  1254. (def_from.deftype=procvardef) and
  1255. (fromtreetype=loadn) and
  1256. { only if the procvar doesn't require any paramters }
  1257. (tprocvardef(def_from).minparacount = 0) then
  1258. begin
  1259. def_from:=tprocvardef(def_from).rettype.def;
  1260. end;
  1261. { we walk the wanted (def_to) types and check then the def_from
  1262. types if there is a conversion possible }
  1263. b:=0;
  1264. case def_to.deftype of
  1265. orddef :
  1266. begin
  1267. case def_from.deftype of
  1268. orddef :
  1269. begin
  1270. doconv:=basedefconverts[basedeftbl[torddef(def_from).typ],basedeftbl[torddef(def_to).typ]];
  1271. b:=1;
  1272. if (doconv=tc_not_possible) or
  1273. ((doconv=tc_int_2_bool) and
  1274. (not explicit) and
  1275. (not is_boolean(def_from))) or
  1276. ((doconv=tc_bool_2_int) and
  1277. (not explicit) and
  1278. (not is_boolean(def_to))) then
  1279. b:=0
  1280. else
  1281. { "punish" bad type conversions :) (JM) }
  1282. if not is_in_limit(def_from,def_to) and
  1283. (def_from.size > def_to.size) then
  1284. b := 2;
  1285. end;
  1286. enumdef :
  1287. begin
  1288. { needed for char(enum) }
  1289. if explicit then
  1290. begin
  1291. doconv:=tc_int_2_int;
  1292. b:=1;
  1293. end;
  1294. end;
  1295. end;
  1296. end;
  1297. stringdef :
  1298. begin
  1299. case def_from.deftype of
  1300. stringdef :
  1301. begin
  1302. doconv:=tc_string_2_string;
  1303. b:=1;
  1304. end;
  1305. orddef :
  1306. begin
  1307. { char to string}
  1308. if is_char(def_from) or
  1309. is_widechar(def_from) then
  1310. begin
  1311. doconv:=tc_char_2_string;
  1312. b:=1;
  1313. end;
  1314. end;
  1315. arraydef :
  1316. begin
  1317. { array of char to string, the length check is done by the firstpass of this node }
  1318. if is_chararray(def_from) or
  1319. (is_equal(tarraydef(def_from).elementtype.def,cchartype.def) and
  1320. is_open_array(def_from)) then
  1321. begin
  1322. doconv:=tc_chararray_2_string;
  1323. if is_open_array(def_from) or
  1324. (is_shortstring(def_to) and
  1325. (def_from.size <= 255)) or
  1326. (is_ansistring(def_to) and
  1327. (def_from.size > 255)) then
  1328. b:=1
  1329. else
  1330. b:=2;
  1331. end;
  1332. end;
  1333. pointerdef :
  1334. begin
  1335. { pchar can be assigned to short/ansistrings,
  1336. but not in tp7 compatible mode }
  1337. if is_pchar(def_from) and not(m_tp7 in aktmodeswitches) then
  1338. begin
  1339. doconv:=tc_pchar_2_string;
  1340. { trefer ansistrings because pchars can overflow shortstrings, }
  1341. { but only if ansistrings are the default (JM) }
  1342. if (is_shortstring(def_to) and
  1343. not(cs_ansistrings in aktlocalswitches)) or
  1344. (is_ansistring(def_to) and
  1345. (cs_ansistrings in aktlocalswitches)) then
  1346. b:=1
  1347. else
  1348. b:=2;
  1349. end;
  1350. end;
  1351. end;
  1352. end;
  1353. floatdef :
  1354. begin
  1355. case def_from.deftype of
  1356. orddef :
  1357. begin { ordinal to real }
  1358. if is_integer(def_from) then
  1359. begin
  1360. doconv:=tc_int_2_real;
  1361. b:=1;
  1362. end;
  1363. end;
  1364. floatdef :
  1365. begin { 2 float types ? }
  1366. if tfloatdef(def_from).typ=tfloatdef(def_to).typ then
  1367. doconv:=tc_equal
  1368. else
  1369. doconv:=tc_real_2_real;
  1370. b:=1;
  1371. end;
  1372. end;
  1373. end;
  1374. enumdef :
  1375. begin
  1376. if (def_from.deftype=enumdef) then
  1377. begin
  1378. if explicit then
  1379. begin
  1380. b:=1;
  1381. doconv:=tc_int_2_int;
  1382. end
  1383. else
  1384. begin
  1385. hd1:=def_from;
  1386. while assigned(tenumdef(hd1).basedef) do
  1387. hd1:=tenumdef(hd1).basedef;
  1388. hd2:=def_to;
  1389. while assigned(tenumdef(hd2).basedef) do
  1390. hd2:=tenumdef(hd2).basedef;
  1391. if (hd1=hd2) then
  1392. begin
  1393. b:=1;
  1394. { because of packenum they can have different sizes! (JM) }
  1395. doconv:=tc_int_2_int;
  1396. end;
  1397. end;
  1398. end;
  1399. end;
  1400. arraydef :
  1401. begin
  1402. { open array is also compatible with a single element of its base type }
  1403. if is_open_array(def_to) and
  1404. is_equal(tarraydef(def_to).elementtype.def,def_from) then
  1405. begin
  1406. doconv:=tc_equal;
  1407. b:=1;
  1408. end
  1409. else
  1410. begin
  1411. case def_from.deftype of
  1412. arraydef :
  1413. begin
  1414. { array constructor -> open array }
  1415. if is_open_array(def_to) and
  1416. is_array_constructor(def_from) then
  1417. begin
  1418. if is_void(tarraydef(def_from).elementtype.def) or
  1419. is_equal(tarraydef(def_to).elementtype.def,tarraydef(def_from).elementtype.def) then
  1420. begin
  1421. doconv:=tc_equal;
  1422. b:=1;
  1423. end
  1424. else
  1425. if isconvertable(tarraydef(def_from).elementtype.def,
  1426. tarraydef(def_to).elementtype.def,hct,arrayconstructorn,false)<>0 then
  1427. begin
  1428. doconv:=hct;
  1429. b:=2;
  1430. end;
  1431. end
  1432. else
  1433. { dynamic array -> open array }
  1434. if is_dynamic_array(def_from) and
  1435. is_open_array(def_to) and
  1436. is_equal(tarraydef(def_to).elementtype.def,tarraydef(def_from).elementtype.def) then
  1437. begin
  1438. doconv := tc_dynarray_2_openarray;
  1439. b := 2;
  1440. end
  1441. else
  1442. { array of tvarrec -> array of const }
  1443. if is_array_of_const(def_to) and
  1444. is_equal(tarraydef(def_to).elementtype.def,tarraydef(def_from).elementtype.def) then
  1445. begin
  1446. doconv:=tc_equal;
  1447. b:=1;
  1448. end;
  1449. end;
  1450. pointerdef :
  1451. begin
  1452. if is_zero_based_array(def_to) and
  1453. is_equal(tpointerdef(def_from).pointertype.def,tarraydef(def_to).elementtype.def) then
  1454. begin
  1455. doconv:=tc_pointer_2_array;
  1456. b:=1;
  1457. end;
  1458. end;
  1459. stringdef :
  1460. begin
  1461. { string to char array }
  1462. if (not is_special_array(def_to)) and
  1463. is_char(tarraydef(def_to).elementtype.def) then
  1464. begin
  1465. doconv:=tc_string_2_chararray;
  1466. b:=1;
  1467. end;
  1468. end;
  1469. orddef:
  1470. begin
  1471. if is_chararray(def_to) and
  1472. is_char(def_from) then
  1473. begin
  1474. doconv:=tc_char_2_chararray;
  1475. b:=2;
  1476. end;
  1477. end;
  1478. recorddef :
  1479. begin
  1480. { tvarrec -> array of constconst }
  1481. if is_array_of_const(def_to) and
  1482. is_equal(def_from,tarraydef(def_to).elementtype.def) then
  1483. begin
  1484. doconv:=tc_equal;
  1485. b:=1;
  1486. end;
  1487. end;
  1488. end;
  1489. end;
  1490. end;
  1491. pointerdef :
  1492. begin
  1493. case def_from.deftype of
  1494. stringdef :
  1495. begin
  1496. { string constant (which can be part of array constructor)
  1497. to zero terminated string constant }
  1498. if (fromtreetype in [arrayconstructorn,stringconstn]) and
  1499. is_pchar(def_to) or is_pwidechar(def_to) then
  1500. begin
  1501. doconv:=tc_cstring_2_pchar;
  1502. b:=1;
  1503. end;
  1504. end;
  1505. orddef :
  1506. begin
  1507. { char constant to zero terminated string constant }
  1508. if (fromtreetype=ordconstn) then
  1509. begin
  1510. if is_equal(def_from,cchartype.def) and
  1511. is_pchar(def_to) then
  1512. begin
  1513. doconv:=tc_cchar_2_pchar;
  1514. b:=1;
  1515. end
  1516. else
  1517. if is_integer(def_from) then
  1518. begin
  1519. doconv:=tc_cord_2_pointer;
  1520. b:=1;
  1521. end;
  1522. end;
  1523. end;
  1524. arraydef :
  1525. begin
  1526. { chararray to pointer }
  1527. if is_zero_based_array(def_from) and
  1528. is_equal(tarraydef(def_from).elementtype.def,tpointerdef(def_to).pointertype.def) then
  1529. begin
  1530. doconv:=tc_array_2_pointer;
  1531. b:=1;
  1532. end;
  1533. end;
  1534. pointerdef :
  1535. begin
  1536. { child class pointer can be assigned to anchestor pointers }
  1537. if (
  1538. (tpointerdef(def_from).pointertype.def.deftype=objectdef) and
  1539. (tpointerdef(def_to).pointertype.def.deftype=objectdef) and
  1540. tobjectdef(tpointerdef(def_from).pointertype.def).is_related(
  1541. tobjectdef(tpointerdef(def_to).pointertype.def))
  1542. ) or
  1543. { all pointers can be assigned to void-pointer }
  1544. is_equal(tpointerdef(def_to).pointertype.def,voidtype.def) or
  1545. { in my opnion, is this not clean pascal }
  1546. { well, but it's handy to use, it isn't ? (FK) }
  1547. is_equal(tpointerdef(def_from).pointertype.def,voidtype.def) then
  1548. begin
  1549. { but don't allow conversion between farpointer-pointer }
  1550. if (tpointerdef(def_to).is_far=tpointerdef(def_from).is_far) then
  1551. begin
  1552. doconv:=tc_equal;
  1553. b:=1;
  1554. end;
  1555. end;
  1556. end;
  1557. procvardef :
  1558. begin
  1559. { procedure variable can be assigned to an void pointer }
  1560. { Not anymore. Use the @ operator now.}
  1561. if not(m_tp_procvar in aktmodeswitches) and
  1562. (tpointerdef(def_to).pointertype.def.deftype=orddef) and
  1563. (torddef(tpointerdef(def_to).pointertype.def).typ=uvoid) then
  1564. begin
  1565. doconv:=tc_equal;
  1566. b:=1;
  1567. end;
  1568. end;
  1569. classrefdef,
  1570. objectdef :
  1571. begin
  1572. { class types and class reference type
  1573. can be assigned to void pointers }
  1574. if (
  1575. is_class_or_interface(def_from) or
  1576. (def_from.deftype=classrefdef)
  1577. ) and
  1578. (tpointerdef(def_to).pointertype.def.deftype=orddef) and
  1579. (torddef(tpointerdef(def_to).pointertype.def).typ=uvoid) then
  1580. begin
  1581. doconv:=tc_equal;
  1582. b:=1;
  1583. end;
  1584. end;
  1585. end;
  1586. end;
  1587. setdef :
  1588. begin
  1589. { automatic arrayconstructor -> set conversion }
  1590. if is_array_constructor(def_from) then
  1591. begin
  1592. doconv:=tc_arrayconstructor_2_set;
  1593. b:=1;
  1594. end;
  1595. end;
  1596. procvardef :
  1597. begin
  1598. { proc -> procvar }
  1599. if (def_from.deftype=procdef) and
  1600. (m_tp_procvar in aktmodeswitches) then
  1601. begin
  1602. doconv:=tc_proc_2_procvar;
  1603. if proc_to_procvar_equal(tprocdef(def_from),tprocvardef(def_to),false) then
  1604. b:=1;
  1605. end
  1606. { procvar -> procvar }
  1607. else
  1608. if (def_from.deftype=procvardef) and
  1609. (proc_to_procvar_equal(tprocvardef(def_from),tprocvardef(def_to),false)) then
  1610. begin
  1611. doconv:=tc_equal;
  1612. b := 2;
  1613. end
  1614. else
  1615. { for example delphi allows the assignement from pointers }
  1616. { to procedure variables }
  1617. if (m_pointer_2_procedure in aktmodeswitches) and
  1618. (def_from.deftype=pointerdef) and
  1619. (tpointerdef(def_from).pointertype.def.deftype=orddef) and
  1620. (torddef(tpointerdef(def_from).pointertype.def).typ=uvoid) then
  1621. begin
  1622. doconv:=tc_equal;
  1623. b:=1;
  1624. end
  1625. else
  1626. { nil is compatible with procvars }
  1627. if (fromtreetype=niln) then
  1628. begin
  1629. doconv:=tc_equal;
  1630. b:=1;
  1631. end;
  1632. end;
  1633. objectdef :
  1634. begin
  1635. { object pascal objects }
  1636. if (def_from.deftype=objectdef) and
  1637. tobjectdef(def_from).is_related(tobjectdef(def_to)) then
  1638. begin
  1639. doconv:=tc_equal;
  1640. b:=1;
  1641. end
  1642. else
  1643. { Class/interface specific }
  1644. if is_class_or_interface(def_to) then
  1645. begin
  1646. { void pointer also for delphi mode }
  1647. if (m_delphi in aktmodeswitches) and
  1648. is_voidpointer(def_from) then
  1649. begin
  1650. doconv:=tc_equal;
  1651. b:=1;
  1652. end
  1653. else
  1654. { nil is compatible with class instances and interfaces }
  1655. if (fromtreetype=niln) then
  1656. begin
  1657. doconv:=tc_equal;
  1658. b:=1;
  1659. end
  1660. { classes can be assigned to interfaces }
  1661. else if is_interface(def_to) and
  1662. is_class(def_from) and
  1663. assigned(tobjectdef(def_from).implementedinterfaces) and
  1664. (tobjectdef(def_from).implementedinterfaces.searchintf(def_to)<>-1) then
  1665. begin
  1666. doconv:=tc_class_2_intf;
  1667. b:=1;
  1668. end
  1669. { Interface 2 GUID handling }
  1670. else if (def_to=tdef(rec_tguid)) and
  1671. (fromtreetype=typen) and
  1672. is_interface(def_from) and
  1673. tobjectdef(def_from).isiidguidvalid then
  1674. begin
  1675. b:=1;
  1676. doconv:=tc_equal;
  1677. end;
  1678. end;
  1679. end;
  1680. classrefdef :
  1681. begin
  1682. { class reference types }
  1683. if (def_from.deftype=classrefdef) then
  1684. begin
  1685. doconv:=tc_equal;
  1686. if tobjectdef(tclassrefdef(def_from).pointertype.def).is_related(
  1687. tobjectdef(tclassrefdef(def_to).pointertype.def)) then
  1688. b:=1;
  1689. end
  1690. else
  1691. { nil is compatible with class references }
  1692. if (fromtreetype=niln) then
  1693. begin
  1694. doconv:=tc_equal;
  1695. b:=1;
  1696. end;
  1697. end;
  1698. filedef :
  1699. begin
  1700. { typed files are all equal to the abstract file type
  1701. name TYPEDFILE in system.pp in is_equal in types.pas
  1702. the problem is that it sholud be also compatible to FILE
  1703. but this would leed to a problem for ASSIGN RESET and REWRITE
  1704. when trying to find the good overloaded function !!
  1705. so all file function are doubled in system.pp
  1706. this is not very beautiful !!}
  1707. if (def_from.deftype=filedef) and
  1708. (
  1709. (
  1710. (tfiledef(def_from).filetyp = ft_typed) and
  1711. (tfiledef(def_to).filetyp = ft_typed) and
  1712. (
  1713. (tfiledef(def_from).typedfiletype.def = tdef(voidtype.def)) or
  1714. (tfiledef(def_to).typedfiletype.def = tdef(voidtype.def))
  1715. )
  1716. ) or
  1717. (
  1718. (
  1719. (tfiledef(def_from).filetyp = ft_untyped) and
  1720. (tfiledef(def_to).filetyp = ft_typed)
  1721. ) or
  1722. (
  1723. (tfiledef(def_from).filetyp = ft_typed) and
  1724. (tfiledef(def_to).filetyp = ft_untyped)
  1725. )
  1726. )
  1727. ) then
  1728. begin
  1729. doconv:=tc_equal;
  1730. b:=1;
  1731. end
  1732. end;
  1733. recorddef :
  1734. begin
  1735. { interface -> guid }
  1736. if is_interface(def_from) and
  1737. (def_to=rec_tguid) then
  1738. begin
  1739. doconv:=tc_intf_2_guid;
  1740. b:=1;
  1741. end
  1742. else
  1743. begin
  1744. { assignment overwritten ?? }
  1745. if assignment_overloaded(def_from,def_to)<>nil then
  1746. b:=2;
  1747. end;
  1748. end;
  1749. else
  1750. begin
  1751. { assignment overwritten ?? }
  1752. if assignment_overloaded(def_from,def_to)<>nil then
  1753. b:=2;
  1754. end;
  1755. end;
  1756. isconvertable:=b;
  1757. end;
  1758. function CheckTypes(def1,def2 : tdef) : boolean;
  1759. var
  1760. s1,s2 : string;
  1761. begin
  1762. if not is_equal(def1,def2) then
  1763. begin
  1764. { Crash prevention }
  1765. if (not assigned(def1)) or (not assigned(def2)) then
  1766. Message(type_e_mismatch)
  1767. else
  1768. begin
  1769. s1:=def1.typename;
  1770. s2:=def2.typename;
  1771. if (s1<>'<unknown type>') and (s2<>'<unknown type>') then
  1772. Message2(type_e_not_equal_types,def1.typename,def2.typename)
  1773. else
  1774. Message(type_e_mismatch);
  1775. end;
  1776. CheckTypes:=false;
  1777. end
  1778. else
  1779. CheckTypes:=true;
  1780. end;
  1781. end.
  1782. {
  1783. $Log$
  1784. Revision 1.69 2002-04-25 20:16:39 peter
  1785. * moved more routines from cga/n386util
  1786. Revision 1.68 2002/04/15 19:08:22 carl
  1787. + target_info.size_of_pointer -> pointer_size
  1788. + some cleanup of unused types/variables
  1789. Revision 1.67 2002/04/07 13:40:29 carl
  1790. + update documentation
  1791. Revision 1.66 2002/04/02 17:11:32 peter
  1792. * tlocation,treference update
  1793. * LOC_CONSTANT added for better constant handling
  1794. * secondadd splitted in multiple routines
  1795. * location_force_reg added for loading a location to a register
  1796. of a specified size
  1797. * secondassignment parses now first the right and then the left node
  1798. (this is compatible with Kylix). This saves a lot of push/pop especially
  1799. with string operations
  1800. * adapted some routines to use the new cg methods
  1801. Revision 1.65 2002/04/01 20:57:14 jonas
  1802. * fixed web bug 1907
  1803. * fixed some other procvar related bugs (all related to accepting procvar
  1804. constructs with either too many or too little parameters)
  1805. (both merged, includes second typo fix of pexpr.pas)
  1806. Revision 1.64 2002/01/24 18:25:53 peter
  1807. * implicit result variable generation for assembler routines
  1808. * removed m_tp modeswitch, use m_tp7 or not(m_fpc) instead
  1809. Revision 1.63 2002/01/24 12:33:53 jonas
  1810. * adapted ranges of native types to int64 (e.g. high cardinal is no
  1811. longer longint($ffffffff), but just $fffffff in psystem)
  1812. * small additional fix in 64bit rangecheck code generation for 32 bit
  1813. processors
  1814. * adaption of ranges required the matching talgorithm used for selecting
  1815. which overloaded procedure to call to be adapted. It should now always
  1816. select the closest match for ordinal parameters.
  1817. + inttostr(qword) in sysstr.inc/sysstrh.inc
  1818. + abs(int64), sqr(int64), sqr(qword) in systemh.inc/generic.inc (previous
  1819. fixes were required to be able to add them)
  1820. * is_in_limit() moved from ncal to types unit, should always be used
  1821. instead of direct comparisons of low/high values of orddefs because
  1822. qword is a special case
  1823. Revision 1.62 2002/01/06 21:50:44 peter
  1824. * proc_to_procvar_equal fixed for procvar-procvar
  1825. Revision 1.61 2002/01/06 12:08:16 peter
  1826. * removed uauto from orddef, use new range_to_basetype generating
  1827. the correct ordinal type for a range
  1828. Revision 1.60 2001/12/17 12:49:08 jonas
  1829. * added type conversion from procvar to procvar (if their arguments are
  1830. convertable, two procvars are convertable too) ("merged")
  1831. Revision 1.59 2001/12/10 14:34:04 jonas
  1832. * fixed type conversions from dynamic arrays to open arrays
  1833. Revision 1.58 2001/12/03 21:48:43 peter
  1834. * freemem change to value parameter
  1835. * torddef low/high range changed to int64
  1836. Revision 1.57 2001/11/14 01:12:45 florian
  1837. * variant paramter passing and functions results fixed
  1838. Revision 1.56 2001/11/02 23:24:12 jonas
  1839. * fixed web bug 1665 (allow char to chararray type conversion) ("merged")
  1840. Revision 1.55 2001/11/02 22:58:09 peter
  1841. * procsym definition rewrite
  1842. Revision 1.54 2001/10/28 17:22:25 peter
  1843. * allow assignment of overloaded procedures to procvars when we know
  1844. which procedure to take
  1845. Revision 1.52 2001/10/22 21:21:09 peter
  1846. * allow enum(enum)
  1847. Revision 1.51 2001/10/22 15:13:49 jonas
  1848. * allow typeconversion of open array-of-char to string
  1849. Revision 1.50 2001/10/20 19:28:39 peter
  1850. * interface 2 guid support
  1851. * guid constants support
  1852. Revision 1.49 2001/10/17 22:41:05 florian
  1853. * several widechar fixes, case works now
  1854. Revision 1.48 2001/10/16 17:15:44 jonas
  1855. * auto-converting from int64 to real is again allowed for all modes
  1856. (it's allowed in Delphi too)
  1857. Revision 1.47 2001/09/03 13:27:41 jonas
  1858. * compilerproc implementation of set addition/substraction/...
  1859. * changed the declaration of some set helpers somewhat to accomodate the
  1860. above change
  1861. * i386 still uses the old code for comparisons of sets, because its
  1862. helpers return the results in the flags
  1863. * dummy tc_normal_2_small_set type conversion because I need the original
  1864. resulttype of the set add nodes
  1865. NOTE: you have to start a cycle with 1.0.5!
  1866. Revision 1.46 2001/09/02 21:15:34 peter
  1867. * don't allow int64->real for delphi mode
  1868. Revision 1.45 2001/08/19 21:11:21 florian
  1869. * some bugs fix:
  1870. - overload; with external procedures fixed
  1871. - better selection of routine to do an overloaded
  1872. type case
  1873. - ... some more
  1874. Revision 1.44 2001/07/08 21:00:16 peter
  1875. * various widestring updates, it works now mostly without charset
  1876. mapping supported
  1877. Revision 1.43 2001/06/29 14:16:57 jonas
  1878. * fixed inconsistent handling of procvars in FPC mode (sometimes @ was
  1879. required to assign the address of a procedure to a procvar, sometimes
  1880. not. Now it is always required) (merged)
  1881. Revision 1.42 2001/05/08 21:06:33 florian
  1882. * some more support for widechars commited especially
  1883. regarding type casting and constants
  1884. Revision 1.41 2001/04/22 22:46:49 florian
  1885. * more variant support
  1886. Revision 1.40 2001/04/18 22:02:00 peter
  1887. * registration of targets and assemblers
  1888. Revision 1.39 2001/04/13 01:22:17 peter
  1889. * symtable change to classes
  1890. * range check generation and errors fixed, make cycle DEBUG=1 works
  1891. * memory leaks fixed
  1892. Revision 1.38 2001/04/04 21:30:47 florian
  1893. * applied several fixes to get the DD8 Delphi Unit compiled
  1894. e.g. "forward"-interfaces are working now
  1895. Revision 1.37 2001/04/02 21:20:35 peter
  1896. * resulttype rewrite
  1897. Revision 1.36 2001/03/23 00:16:07 florian
  1898. + some stuff to compile FreeCLX added
  1899. Revision 1.35 2001/03/03 12:38:33 jonas
  1900. + support for arraydefs in is_signed (for their rangetype, used in rangechecks)
  1901. Revision 1.34 2001/02/26 19:44:55 peter
  1902. * merged generic m68k updates from fixes branch
  1903. Revision 1.33 2001/02/26 12:47:46 jonas
  1904. * fixed bug in type checking for compatibility of set elements (merged)
  1905. * released fix in options.pas from Carl also for FPC (merged)
  1906. Revision 1.32 2001/02/20 21:44:25 peter
  1907. * tvarrec -> array of const fixed
  1908. Revision 1.31 2001/01/22 11:20:15 jonas
  1909. * fixed web bug 1363 (merged)
  1910. Revision 1.30 2001/01/08 21:43:38 peter
  1911. * string isn't compatible with array of char
  1912. Revision 1.29 2000/12/25 00:07:30 peter
  1913. + new tlinkedlist class (merge of old tstringqueue,tcontainer and
  1914. tlinkedlist objects)
  1915. Revision 1.28 2000/12/22 22:38:12 peter
  1916. * fixed bug #1286
  1917. Revision 1.27 2000/12/20 15:59:40 jonas
  1918. - removed obsolete special case for range checking of cardinal constants
  1919. at compile time
  1920. Revision 1.26 2000/12/11 19:13:54 jonas
  1921. * fixed range checking of cardinal constants
  1922. * fixed range checking of "qword constants" (they don't really exist,
  1923. but values > high(int64) were set to zero if assigned to qword)
  1924. Revision 1.25 2000/12/08 14:06:11 jonas
  1925. * fix for web bug 1245: arrays of char with size >255 are now passed to
  1926. overloaded procedures which expect ansistrings instead of shortstrings
  1927. if possible
  1928. * pointer to array of chars (when using $t+) are now also considered
  1929. pchars
  1930. Revision 1.24 2000/11/20 15:52:47 jonas
  1931. * testrange now always cuts a constant to the size of the destination
  1932. if a rangeerror occurred
  1933. * changed an "and $ffffffff" to "and (int64($fffffff) shl 4 + $f" to
  1934. work around the constant evaluation problem we currently have
  1935. Revision 1.23 2000/11/13 14:42:41 jonas
  1936. * fix in testrange so that 64bit constants are properly truncated when
  1937. assigned to 32bit vars
  1938. Revision 1.22 2000/11/13 11:30:55 florian
  1939. * some bugs with interfaces and NIL fixed
  1940. Revision 1.21 2000/11/12 23:24:12 florian
  1941. * interfaces are basically running
  1942. Revision 1.20 2000/11/11 16:13:31 peter
  1943. * farpointer and normal pointer aren't compatible
  1944. Revision 1.19 2000/11/06 22:30:30 peter
  1945. * more fixes
  1946. Revision 1.18 2000/11/04 14:25:22 florian
  1947. + merged Attila's changes for interfaces, not tested yet
  1948. Revision 1.17 2000/10/31 22:30:13 peter
  1949. * merged asm result patch part 2
  1950. Revision 1.16 2000/10/31 22:02:55 peter
  1951. * symtable splitted, no real code changes
  1952. Revision 1.15 2000/10/21 18:16:12 florian
  1953. * a lot of changes:
  1954. - basic dyn. array support
  1955. - basic C++ support
  1956. - some work for interfaces done
  1957. ....
  1958. Revision 1.14 2000/10/14 10:14:56 peter
  1959. * moehrendorf oct 2000 rewrite
  1960. Revision 1.13 2000/10/01 19:48:26 peter
  1961. * lot of compile updates for cg11
  1962. Revision 1.12 2000/09/30 16:08:46 peter
  1963. * more cg11 updates
  1964. Revision 1.11 2000/09/24 15:06:32 peter
  1965. * use defines.inc
  1966. Revision 1.10 2000/09/18 12:31:15 jonas
  1967. * fixed bug in push_addr_param for arrays (merged from fixes branch)
  1968. Revision 1.9 2000/09/10 20:16:21 peter
  1969. * array of const isn't equal with array of <type> (merged)
  1970. Revision 1.8 2000/08/19 19:51:03 peter
  1971. * fixed bug with comparing constsym strings
  1972. Revision 1.7 2000/08/16 13:06:07 florian
  1973. + support of 64 bit integer constants
  1974. Revision 1.6 2000/08/13 13:07:18 peter
  1975. * equal_paras now also checks default parameter value
  1976. Revision 1.5 2000/08/12 06:49:22 florian
  1977. + case statement for int64/qword implemented
  1978. Revision 1.4 2000/08/08 19:26:41 peter
  1979. * equal_constsym() needed for default para
  1980. Revision 1.3 2000/07/13 12:08:28 michael
  1981. + patched to 1.1.0 with former 1.09patch from peter
  1982. Revision 1.2 2000/07/13 11:32:53 michael
  1983. + removed logs
  1984. }