defbase.pas 75 KB

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