defbase.pas 74 KB

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