defbase.pas 76 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098
  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:=true
  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. begin
  1140. internal_assignment_overloaded:=nil;
  1141. p := nil;
  1142. if not assigned(overloaded_operators[_ASSIGNMENT]) then
  1143. exit;
  1144. { look for an exact match first, from start of list }
  1145. internal_assignment_overloaded:=overloaded_operators[_ASSIGNMENT].
  1146. search_procdef_byretdef_by1paradef(to_def,from_def,dm_exact,
  1147. p);
  1148. if assigned(internal_assignment_overloaded) then
  1149. exit;
  1150. { .... then look for an equal match, from start of list }
  1151. internal_assignment_overloaded:=overloaded_operators[_ASSIGNMENT].
  1152. search_procdef_byretdef_by1paradef(to_def,from_def,dm_equal,
  1153. p);
  1154. if assigned(internal_assignment_overloaded) then
  1155. exit;
  1156. { .... then for convert level 1, continue from where we were at }
  1157. internal_assignment_overloaded:=overloaded_operators[_ASSIGNMENT].
  1158. search_procdef_byretdef_by1paradef(to_def,from_def,dm_convertl1,
  1159. overload_procs);
  1160. end;
  1161. function assignment_overloaded(from_def,to_def : tdef) : tprocdef;
  1162. var
  1163. p : pprocdeflist;
  1164. begin
  1165. p:=nil;
  1166. assignment_overloaded:=nil;
  1167. assignment_overloaded:=internal_assignment_overloaded(
  1168. from_def, to_def, p);
  1169. end;
  1170. { Returns:
  1171. 0 - Not convertable
  1172. 1 - Convertable
  1173. 2 - Convertable, but not first choice
  1174. }
  1175. function isconvertable(def_from,def_to : tdef;
  1176. var doconv : tconverttype;
  1177. fromtreetype : tnodetype;
  1178. explicit : boolean) : byte;
  1179. var
  1180. p: pprocdeflist;
  1181. begin
  1182. p:=nil;
  1183. isconvertable:=overloaded_assignment_isconvertable(def_from,def_to,
  1184. doconv, fromtreetype, explicit,p);
  1185. end;
  1186. function overloaded_assignment_isconvertable(def_from,def_to : tdef;
  1187. var doconv : tconverttype;
  1188. fromtreetype : tnodetype;
  1189. explicit : boolean; var overload_procs : pprocdeflist) : byte;
  1190. { Tbasetype:
  1191. uvoid,
  1192. u8bit,u16bit,u32bit,u64bit,
  1193. s8bit,s16bit,s32bit,s64bit,
  1194. bool8bit,bool16bit,bool32bit,
  1195. uchar,uwidechar }
  1196. type
  1197. tbasedef=(bvoid,bchar,bint,bbool);
  1198. const
  1199. basedeftbl:array[tbasetype] of tbasedef =
  1200. (bvoid,
  1201. bint,bint,bint,bint,
  1202. bint,bint,bint,bint,
  1203. bbool,bbool,bbool,
  1204. bchar,bchar);
  1205. basedefconverts : array[tbasedef,tbasedef] of tconverttype =
  1206. ((tc_not_possible,tc_not_possible,tc_not_possible,tc_not_possible),
  1207. (tc_not_possible,tc_char_2_char,tc_not_possible,tc_not_possible),
  1208. (tc_not_possible,tc_not_possible,tc_int_2_int,tc_int_2_bool),
  1209. (tc_not_possible,tc_not_possible,tc_bool_2_int,tc_bool_2_bool));
  1210. var
  1211. b : byte;
  1212. hd1,hd2 : tdef;
  1213. hct : tconverttype;
  1214. hd3 : tobjectdef;
  1215. begin
  1216. { safety check }
  1217. if not(assigned(def_from) and assigned(def_to)) then
  1218. begin
  1219. overloaded_assignment_isconvertable :=0;
  1220. exit;
  1221. end;
  1222. { tp7 procvar def support, in tp7 a procvar is always called, if the
  1223. procvar is passed explicit a addrn would be there }
  1224. if (m_tp_procvar in aktmodeswitches) and
  1225. (def_from.deftype=procvardef) and
  1226. (fromtreetype=loadn) and
  1227. { only if the procvar doesn't require any paramters }
  1228. (tprocvardef(def_from).minparacount = 0) then
  1229. begin
  1230. def_from:=tprocvardef(def_from).rettype.def;
  1231. end;
  1232. { we walk the wanted (def_to) types and check then the def_from
  1233. types if there is a conversion possible }
  1234. b:=0;
  1235. case def_to.deftype of
  1236. orddef :
  1237. begin
  1238. case def_from.deftype of
  1239. orddef :
  1240. begin
  1241. doconv:=basedefconverts[basedeftbl[torddef(def_from).typ],basedeftbl[torddef(def_to).typ]];
  1242. b:=1;
  1243. if (doconv=tc_not_possible) or
  1244. ((doconv=tc_int_2_bool) and
  1245. (not explicit) and
  1246. (not is_boolean(def_from))) or
  1247. ((doconv=tc_bool_2_int) and
  1248. (not explicit) and
  1249. (not is_boolean(def_to))) then
  1250. b:=0
  1251. else
  1252. { "punish" bad type conversions :) (JM) }
  1253. if not is_in_limit(def_from,def_to) and
  1254. (def_from.size > def_to.size) then
  1255. b := 2;
  1256. end;
  1257. enumdef :
  1258. begin
  1259. { needed for char(enum) }
  1260. if explicit then
  1261. begin
  1262. doconv:=tc_int_2_int;
  1263. b:=1;
  1264. end;
  1265. end;
  1266. end;
  1267. end;
  1268. stringdef :
  1269. begin
  1270. case def_from.deftype of
  1271. stringdef :
  1272. begin
  1273. doconv:=tc_string_2_string;
  1274. b:=1;
  1275. end;
  1276. orddef :
  1277. begin
  1278. { char to string}
  1279. if is_char(def_from) or
  1280. is_widechar(def_from) then
  1281. begin
  1282. doconv:=tc_char_2_string;
  1283. b:=1;
  1284. end;
  1285. end;
  1286. arraydef :
  1287. begin
  1288. { array of char to string, the length check is done by the firstpass of this node }
  1289. if is_chararray(def_from) or
  1290. (is_equal(tarraydef(def_from).elementtype.def,cchartype.def) and
  1291. is_open_array(def_from)) then
  1292. begin
  1293. doconv:=tc_chararray_2_string;
  1294. if is_open_array(def_from) or
  1295. (is_shortstring(def_to) and
  1296. (def_from.size <= 255)) or
  1297. (is_ansistring(def_to) and
  1298. (def_from.size > 255)) then
  1299. b:=1
  1300. else
  1301. b:=2;
  1302. end;
  1303. end;
  1304. pointerdef :
  1305. begin
  1306. { pchar can be assigned to short/ansistrings,
  1307. but not in tp7 compatible mode }
  1308. if is_pchar(def_from) and not(m_tp7 in aktmodeswitches) then
  1309. begin
  1310. doconv:=tc_pchar_2_string;
  1311. { trefer ansistrings because pchars can overflow shortstrings, }
  1312. { but only if ansistrings are the default (JM) }
  1313. if (is_shortstring(def_to) and
  1314. not(cs_ansistrings in aktlocalswitches)) or
  1315. (is_ansistring(def_to) and
  1316. (cs_ansistrings in aktlocalswitches)) then
  1317. b:=1
  1318. else
  1319. b:=2;
  1320. end;
  1321. end;
  1322. end;
  1323. end;
  1324. floatdef :
  1325. begin
  1326. case def_from.deftype of
  1327. orddef :
  1328. begin { ordinal to real }
  1329. if is_integer(def_from) then
  1330. begin
  1331. doconv:=tc_int_2_real;
  1332. b:=1;
  1333. end;
  1334. end;
  1335. floatdef :
  1336. begin { 2 float types ? }
  1337. if tfloatdef(def_from).typ=tfloatdef(def_to).typ then
  1338. doconv:=tc_equal
  1339. else
  1340. doconv:=tc_real_2_real;
  1341. b:=1;
  1342. end;
  1343. end;
  1344. end;
  1345. enumdef :
  1346. begin
  1347. if (def_from.deftype=enumdef) then
  1348. begin
  1349. if explicit then
  1350. begin
  1351. b:=1;
  1352. doconv:=tc_int_2_int;
  1353. end
  1354. else
  1355. begin
  1356. hd1:=def_from;
  1357. while assigned(tenumdef(hd1).basedef) do
  1358. hd1:=tenumdef(hd1).basedef;
  1359. hd2:=def_to;
  1360. while assigned(tenumdef(hd2).basedef) do
  1361. hd2:=tenumdef(hd2).basedef;
  1362. if (hd1=hd2) then
  1363. begin
  1364. b:=1;
  1365. { because of packenum they can have different sizes! (JM) }
  1366. doconv:=tc_int_2_int;
  1367. end;
  1368. end;
  1369. end;
  1370. end;
  1371. arraydef :
  1372. begin
  1373. { open array is also compatible with a single element of its base type }
  1374. if is_open_array(def_to) and
  1375. is_equal(tarraydef(def_to).elementtype.def,def_from) then
  1376. begin
  1377. doconv:=tc_equal;
  1378. b:=1;
  1379. end
  1380. else if is_dynamic_array(def_to) and
  1381. { nil is compatible with dyn. arrays }
  1382. (fromtreetype=niln) then
  1383. begin
  1384. doconv:=tc_equal;
  1385. b:=1;
  1386. end
  1387. else
  1388. begin
  1389. case def_from.deftype of
  1390. arraydef :
  1391. begin
  1392. { array constructor -> open array }
  1393. if is_open_array(def_to) and
  1394. is_array_constructor(def_from) then
  1395. begin
  1396. if is_void(tarraydef(def_from).elementtype.def) or
  1397. is_equal(tarraydef(def_to).elementtype.def,tarraydef(def_from).elementtype.def) then
  1398. begin
  1399. doconv:=tc_equal;
  1400. b:=1;
  1401. end
  1402. else
  1403. if isconvertable(tarraydef(def_from).elementtype.def,
  1404. tarraydef(def_to).elementtype.def,hct,arrayconstructorn,false)<>0 then
  1405. begin
  1406. doconv:=hct;
  1407. b:=2;
  1408. end;
  1409. end
  1410. else
  1411. { dynamic array -> open array }
  1412. if is_dynamic_array(def_from) and
  1413. is_open_array(def_to) and
  1414. is_equal(tarraydef(def_to).elementtype.def,tarraydef(def_from).elementtype.def) then
  1415. begin
  1416. doconv := tc_dynarray_2_openarray;
  1417. b := 2;
  1418. end
  1419. else
  1420. { array of tvarrec -> array of const }
  1421. if is_array_of_const(def_to) and
  1422. is_equal(tarraydef(def_to).elementtype.def,tarraydef(def_from).elementtype.def) then
  1423. begin
  1424. doconv:=tc_equal;
  1425. b:=1;
  1426. end;
  1427. end;
  1428. pointerdef :
  1429. begin
  1430. if is_zero_based_array(def_to) and
  1431. is_equal(tpointerdef(def_from).pointertype.def,tarraydef(def_to).elementtype.def) then
  1432. begin
  1433. doconv:=tc_pointer_2_array;
  1434. b:=1;
  1435. end;
  1436. end;
  1437. stringdef :
  1438. begin
  1439. { string to char array }
  1440. if (not is_special_array(def_to)) and
  1441. is_char(tarraydef(def_to).elementtype.def) then
  1442. begin
  1443. doconv:=tc_string_2_chararray;
  1444. b:=1;
  1445. end;
  1446. end;
  1447. orddef:
  1448. begin
  1449. if is_chararray(def_to) and
  1450. is_char(def_from) then
  1451. begin
  1452. doconv:=tc_char_2_chararray;
  1453. b:=2;
  1454. end;
  1455. end;
  1456. recorddef :
  1457. begin
  1458. { tvarrec -> array of const }
  1459. if is_array_of_const(def_to) and
  1460. is_equal(def_from,tarraydef(def_to).elementtype.def) then
  1461. begin
  1462. doconv:=tc_equal;
  1463. b:=1;
  1464. end;
  1465. end;
  1466. end;
  1467. end;
  1468. end;
  1469. pointerdef :
  1470. begin
  1471. case def_from.deftype of
  1472. stringdef :
  1473. begin
  1474. { string constant (which can be part of array constructor)
  1475. to zero terminated string constant }
  1476. if (fromtreetype in [arrayconstructorn,stringconstn]) and
  1477. is_pchar(def_to) or is_pwidechar(def_to) then
  1478. begin
  1479. doconv:=tc_cstring_2_pchar;
  1480. b:=1;
  1481. end;
  1482. end;
  1483. orddef :
  1484. begin
  1485. { char constant to zero terminated string constant }
  1486. if (fromtreetype=ordconstn) then
  1487. begin
  1488. if is_equal(def_from,cchartype.def) and
  1489. is_pchar(def_to) then
  1490. begin
  1491. doconv:=tc_cchar_2_pchar;
  1492. b:=1;
  1493. end
  1494. else
  1495. if is_integer(def_from) then
  1496. begin
  1497. doconv:=tc_cord_2_pointer;
  1498. b:=1;
  1499. end;
  1500. end;
  1501. end;
  1502. arraydef :
  1503. begin
  1504. { chararray to pointer }
  1505. if is_zero_based_array(def_from) and
  1506. is_equal(tarraydef(def_from).elementtype.def,tpointerdef(def_to).pointertype.def) then
  1507. begin
  1508. doconv:=tc_array_2_pointer;
  1509. b:=1;
  1510. end;
  1511. end;
  1512. pointerdef :
  1513. begin
  1514. { child class pointer can be assigned to anchestor pointers }
  1515. if (
  1516. (tpointerdef(def_from).pointertype.def.deftype=objectdef) and
  1517. (tpointerdef(def_to).pointertype.def.deftype=objectdef) and
  1518. tobjectdef(tpointerdef(def_from).pointertype.def).is_related(
  1519. tobjectdef(tpointerdef(def_to).pointertype.def))
  1520. ) or
  1521. { all pointers can be assigned to void-pointer }
  1522. is_equal(tpointerdef(def_to).pointertype.def,voidtype.def) or
  1523. { in my opnion, is this not clean pascal }
  1524. { well, but it's handy to use, it isn't ? (FK) }
  1525. is_equal(tpointerdef(def_from).pointertype.def,voidtype.def) then
  1526. begin
  1527. { but don't allow conversion between farpointer-pointer }
  1528. if (tpointerdef(def_to).is_far=tpointerdef(def_from).is_far) then
  1529. begin
  1530. doconv:=tc_equal;
  1531. b:=1;
  1532. end;
  1533. end;
  1534. end;
  1535. procvardef :
  1536. begin
  1537. { procedure variable can be assigned to an void pointer }
  1538. { Not anymore. Use the @ operator now.}
  1539. if not(m_tp_procvar in aktmodeswitches) and
  1540. (tpointerdef(def_to).pointertype.def.deftype=orddef) and
  1541. (torddef(tpointerdef(def_to).pointertype.def).typ=uvoid) then
  1542. begin
  1543. doconv:=tc_equal;
  1544. b:=1;
  1545. end;
  1546. end;
  1547. classrefdef,
  1548. objectdef :
  1549. begin
  1550. { class types and class reference type
  1551. can be assigned to void pointers }
  1552. if (
  1553. is_class_or_interface(def_from) or
  1554. (def_from.deftype=classrefdef)
  1555. ) and
  1556. (tpointerdef(def_to).pointertype.def.deftype=orddef) and
  1557. (torddef(tpointerdef(def_to).pointertype.def).typ=uvoid) then
  1558. begin
  1559. doconv:=tc_equal;
  1560. b:=1;
  1561. end;
  1562. end;
  1563. end;
  1564. end;
  1565. setdef :
  1566. begin
  1567. { automatic arrayconstructor -> set conversion }
  1568. if is_array_constructor(def_from) then
  1569. begin
  1570. doconv:=tc_arrayconstructor_2_set;
  1571. b:=1;
  1572. end;
  1573. end;
  1574. procvardef :
  1575. begin
  1576. { proc -> procvar }
  1577. if (def_from.deftype=procdef) and
  1578. (m_tp_procvar in aktmodeswitches) then
  1579. begin
  1580. doconv:=tc_proc_2_procvar;
  1581. if proc_to_procvar_equal(tprocdef(def_from),tprocvardef(def_to),false) then
  1582. b:=1;
  1583. end
  1584. { procvar -> procvar }
  1585. else
  1586. if (def_from.deftype=procvardef) and
  1587. (proc_to_procvar_equal(tprocvardef(def_from),tprocvardef(def_to),false)) then
  1588. begin
  1589. doconv:=tc_equal;
  1590. b := 2;
  1591. end
  1592. else
  1593. { for example delphi allows the assignement from pointers }
  1594. { to procedure variables }
  1595. if (m_pointer_2_procedure in aktmodeswitches) and
  1596. (def_from.deftype=pointerdef) and
  1597. (tpointerdef(def_from).pointertype.def.deftype=orddef) and
  1598. (torddef(tpointerdef(def_from).pointertype.def).typ=uvoid) then
  1599. begin
  1600. doconv:=tc_equal;
  1601. b:=1;
  1602. end
  1603. else
  1604. { nil is compatible with procvars }
  1605. if (fromtreetype=niln) then
  1606. begin
  1607. doconv:=tc_equal;
  1608. b:=1;
  1609. end;
  1610. end;
  1611. objectdef :
  1612. begin
  1613. { object pascal objects }
  1614. if (def_from.deftype=objectdef) and
  1615. tobjectdef(def_from).is_related(tobjectdef(def_to)) then
  1616. begin
  1617. doconv:=tc_equal;
  1618. b:=1;
  1619. end
  1620. else
  1621. { Class/interface specific }
  1622. if is_class_or_interface(def_to) then
  1623. begin
  1624. { void pointer also for delphi mode }
  1625. if (m_delphi in aktmodeswitches) and
  1626. is_voidpointer(def_from) then
  1627. begin
  1628. doconv:=tc_equal;
  1629. b:=1;
  1630. end
  1631. else
  1632. { nil is compatible with class instances and interfaces }
  1633. if (fromtreetype=niln) then
  1634. begin
  1635. doconv:=tc_equal;
  1636. b:=1;
  1637. end
  1638. { classes can be assigned to interfaces }
  1639. else if is_interface(def_to) and
  1640. is_class(def_from) and
  1641. assigned(tobjectdef(def_from).implementedinterfaces) then
  1642. begin
  1643. { we've to search in parent classes as well }
  1644. hd3:=tobjectdef(def_from);
  1645. while assigned(hd3) do
  1646. begin
  1647. if hd3.implementedinterfaces.searchintf(def_to)<>-1 then
  1648. begin
  1649. doconv:=tc_class_2_intf;
  1650. b:=1;
  1651. break;
  1652. end;
  1653. hd3:=hd3.childof;
  1654. end;
  1655. end
  1656. { Interface 2 GUID handling }
  1657. else if (def_to=tdef(rec_tguid)) and
  1658. (fromtreetype=typen) and
  1659. is_interface(def_from) and
  1660. tobjectdef(def_from).isiidguidvalid then
  1661. begin
  1662. b:=1;
  1663. doconv:=tc_equal;
  1664. end;
  1665. end;
  1666. end;
  1667. classrefdef :
  1668. begin
  1669. { class reference types }
  1670. if (def_from.deftype=classrefdef) then
  1671. begin
  1672. doconv:=tc_equal;
  1673. if tobjectdef(tclassrefdef(def_from).pointertype.def).is_related(
  1674. tobjectdef(tclassrefdef(def_to).pointertype.def)) then
  1675. b:=1;
  1676. end
  1677. else
  1678. { nil is compatible with class references }
  1679. if (fromtreetype=niln) then
  1680. begin
  1681. doconv:=tc_equal;
  1682. b:=1;
  1683. end;
  1684. end;
  1685. filedef :
  1686. begin
  1687. { typed files are all equal to the abstract file type
  1688. name TYPEDFILE in system.pp in is_equal in types.pas
  1689. the problem is that it sholud be also compatible to FILE
  1690. but this would leed to a problem for ASSIGN RESET and REWRITE
  1691. when trying to find the good overloaded function !!
  1692. so all file function are doubled in system.pp
  1693. this is not very beautiful !!}
  1694. if (def_from.deftype=filedef) and
  1695. (
  1696. (
  1697. (tfiledef(def_from).filetyp = ft_typed) and
  1698. (tfiledef(def_to).filetyp = ft_typed) and
  1699. (
  1700. (tfiledef(def_from).typedfiletype.def = tdef(voidtype.def)) or
  1701. (tfiledef(def_to).typedfiletype.def = tdef(voidtype.def))
  1702. )
  1703. ) or
  1704. (
  1705. (
  1706. (tfiledef(def_from).filetyp = ft_untyped) and
  1707. (tfiledef(def_to).filetyp = ft_typed)
  1708. ) or
  1709. (
  1710. (tfiledef(def_from).filetyp = ft_typed) and
  1711. (tfiledef(def_to).filetyp = ft_untyped)
  1712. )
  1713. )
  1714. ) then
  1715. begin
  1716. doconv:=tc_equal;
  1717. b:=1;
  1718. end
  1719. end;
  1720. recorddef :
  1721. begin
  1722. { interface -> guid }
  1723. if is_interface(def_from) and
  1724. (def_to=rec_tguid) then
  1725. begin
  1726. doconv:=tc_intf_2_guid;
  1727. b:=1;
  1728. end
  1729. else
  1730. begin
  1731. { assignment overwritten ?? }
  1732. if internal_assignment_overloaded(def_from,def_to,overload_procs)<>nil then
  1733. b:=2;
  1734. end;
  1735. end;
  1736. formaldef:
  1737. {Just about everything can be converted to a formaldef...}
  1738. if not (def_from.deftype in [abstractdef,errordef]) then
  1739. b:=1;
  1740. else
  1741. begin
  1742. { assignment overwritten ?? }
  1743. if internal_assignment_overloaded(def_from,def_to,overload_procs)<>nil then
  1744. b:=2;
  1745. end;
  1746. end;
  1747. overloaded_assignment_isconvertable :=b;
  1748. end;
  1749. function CheckTypes(def1,def2 : tdef) : boolean;
  1750. var
  1751. s1,s2 : string;
  1752. begin
  1753. CheckTypes:=False;
  1754. if not is_equal(def1,def2) then
  1755. begin
  1756. { Crash prevention }
  1757. if (not assigned(def1)) or (not assigned(def2)) then
  1758. Message(type_e_mismatch)
  1759. else
  1760. begin
  1761. if not is_subequal(def1,def2) then
  1762. begin
  1763. s1:=def1.typename;
  1764. s2:=def2.typename;
  1765. Message2(type_e_not_equal_types,def1.typename,def2.typename);
  1766. end
  1767. else
  1768. CheckTypes := true;
  1769. end;
  1770. end
  1771. else
  1772. CheckTypes := True;
  1773. end;
  1774. end.
  1775. {
  1776. $Log$
  1777. Revision 1.15 2002-10-05 00:50:01 peter
  1778. * check parameters from left to right in equal_paras, so default
  1779. parameters are checked at the end
  1780. Revision 1.14 2002/09/30 07:00:44 florian
  1781. * fixes to common code to get the alpha compiler compiled applied
  1782. Revision 1.13 2002/09/22 14:02:34 carl
  1783. * stack checking cannot be called before system unit is initialized
  1784. * MC68020 define
  1785. Revision 1.12 2002/09/16 14:11:12 peter
  1786. * add argument to equal_paras() to support default values or not
  1787. Revision 1.11 2002/09/15 17:54:46 peter
  1788. * allow default parameters in equal_paras
  1789. Revision 1.10 2002/09/08 11:10:17 carl
  1790. * bugfix 2109 (bad imho, but only way)
  1791. Revision 1.9 2002/09/07 15:25:02 peter
  1792. * old logs removed and tabs fixed
  1793. Revision 1.8 2002/09/07 09:16:55 carl
  1794. * fix my stupid copy and paste bug
  1795. Revision 1.7 2002/09/06 19:58:31 carl
  1796. * start bugfix 1996
  1797. * 64-bit typed constant now work correctly and fully (bugfix 2001)
  1798. Revision 1.6 2002/08/20 10:31:26 daniel
  1799. * Tcallnode.det_resulttype rewritten
  1800. Revision 1.5 2002/08/12 20:39:17 florian
  1801. * casting of classes to interface fixed when the interface was
  1802. implemented by a parent class
  1803. Revision 1.4 2002/08/12 14:17:56 florian
  1804. * nil is now recognized as being compatible with a dynamic array
  1805. Revision 1.3 2002/08/05 18:27:48 carl
  1806. + more more more documentation
  1807. + first version include/exclude (can't test though, not enough scratch for i386 :()...
  1808. Revision 1.2 2002/07/23 09:51:22 daniel
  1809. * Tried to make Tprocsym.defs protected. I didn't succeed but the cleanups
  1810. are worth comitting.
  1811. Revision 1.1 2002/07/20 11:57:53 florian
  1812. * types.pas renamed to defbase.pas because D6 contains a types
  1813. unit so this would conflicts if D6 programms are compiled
  1814. + Willamette/SSE2 instructions to assembler added
  1815. Revision 1.75 2002/07/11 14:41:32 florian
  1816. * start of the new generic parameter handling
  1817. Revision 1.74 2002/07/01 16:23:54 peter
  1818. * cg64 patch
  1819. * basics for currency
  1820. * asnode updates for class and interface (not finished)
  1821. Revision 1.73 2002/05/18 13:34:21 peter
  1822. * readded missing revisions
  1823. Revision 1.72 2002/05/16 19:46:47 carl
  1824. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  1825. + try to fix temp allocation (still in ifdef)
  1826. + generic constructor calls
  1827. + start of tassembler / tmodulebase class cleanup
  1828. Revision 1.70 2002/05/12 16:53:16 peter
  1829. * moved entry and exitcode to ncgutil and cgobj
  1830. * foreach gets extra argument for passing local data to the
  1831. iterator function
  1832. * -CR checks also class typecasts at runtime by changing them
  1833. into as
  1834. * fixed compiler to cycle with the -CR option
  1835. * fixed stabs with elf writer, finally the global variables can
  1836. be watched
  1837. * removed a lot of routines from cga unit and replaced them by
  1838. calls to cgobj
  1839. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  1840. u32bit then the other is typecasted also to u32bit without giving
  1841. a rangecheck warning/error.
  1842. * fixed pascal calling method with reversing also the high tree in
  1843. the parast, detected by tcalcst3 test
  1844. Revision 1.69 2002/04/25 20:16:39 peter
  1845. * moved more routines from cga/n386util
  1846. Revision 1.68 2002/04/15 19:08:22 carl
  1847. + target_info.size_of_pointer -> pointer_size
  1848. + some cleanup of unused types/variables
  1849. Revision 1.67 2002/04/07 13:40:29 carl
  1850. + update documentation
  1851. Revision 1.66 2002/04/02 17:11:32 peter
  1852. * tlocation,treference update
  1853. * LOC_CONSTANT added for better constant handling
  1854. * secondadd splitted in multiple routines
  1855. * location_force_reg added for loading a location to a register
  1856. of a specified size
  1857. * secondassignment parses now first the right and then the left node
  1858. (this is compatible with Kylix). This saves a lot of push/pop especially
  1859. with string operations
  1860. * adapted some routines to use the new cg methods
  1861. Revision 1.65 2002/04/01 20:57:14 jonas
  1862. * fixed web bug 1907
  1863. * fixed some other procvar related bugs (all related to accepting procvar
  1864. constructs with either too many or too little parameters)
  1865. (both merged, includes second typo fix of pexpr.pas)
  1866. Revision 1.64 2002/01/24 18:25:53 peter
  1867. * implicit result variable generation for assembler routines
  1868. * removed m_tp modeswitch, use m_tp7 or not(m_fpc) instead
  1869. Revision 1.63 2002/01/24 12:33:53 jonas
  1870. * adapted ranges of native types to int64 (e.g. high cardinal is no
  1871. longer longint($ffffffff), but just $fffffff in psystem)
  1872. * small additional fix in 64bit rangecheck code generation for 32 bit
  1873. processors
  1874. * adaption of ranges required the matching talgorithm used for selecting
  1875. which overloaded procedure to call to be adapted. It should now always
  1876. select the closest match for ordinal parameters.
  1877. + inttostr(qword) in sysstr.inc/sysstrh.inc
  1878. + abs(int64), sqr(int64), sqr(qword) in systemh.inc/generic.inc (previous
  1879. fixes were required to be able to add them)
  1880. * is_in_limit() moved from ncal to types unit, should always be used
  1881. instead of direct comparisons of low/high values of orddefs because
  1882. qword is a special case
  1883. }