2
0

defbase.pas 77 KB

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