defutil.pas 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993
  1. {
  2. Copyright (c) 1998-2006 by Florian Klaempfl
  3. This unit provides some help routines for type handling
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit defutil;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. globtype,globals,constexp,
  22. symconst,symtype,symdef,
  23. cgbase,cpubase;
  24. type
  25. tmmxtype = (mmxno,mmxu8bit,mmxs8bit,mmxu16bit,mmxs16bit,
  26. mmxu32bit,mmxs32bit,mmxfixed16,mmxsingle,mmxs64bit,mmxu64bit);
  27. {*****************************************************************************
  28. Basic type functions
  29. *****************************************************************************}
  30. {# Returns true, if definition defines an ordinal type }
  31. function is_ordinal(def : tdef) : boolean;
  32. {# Returns true, if definition defines a string type }
  33. function is_string(def : tdef): boolean;
  34. {# Returns True, if definition defines a type that behaves like a string,
  35. namely that can be joined and compared with another string-like type }
  36. function is_stringlike(def : tdef) : boolean;
  37. {# Returns True, if definition defines an enumeration type }
  38. function is_enum(def : tdef) : boolean;
  39. {# Returns True, if definition defines a set type }
  40. function is_set(def : tdef) : boolean;
  41. {# Returns the minimal integer value of the type }
  42. function get_min_value(def : tdef) : TConstExprInt;
  43. {# Returns the maximal integer value of the type }
  44. function get_max_value(def : tdef) : TConstExprInt;
  45. {# Returns basetype of the specified integer range }
  46. function range_to_basetype(const l,h:TConstExprInt):tordtype;
  47. procedure range_to_type(const l,h:TConstExprInt;var def:tdef);
  48. procedure int_to_type(const v:TConstExprInt;var def:tdef);
  49. {# Return true if the type (orddef or enumdef) spans its entire bitrange }
  50. function spans_entire_range(def: tdef): boolean;
  51. {# Returns true, if definition defines an integer type }
  52. function is_integer(def : tdef) : boolean;
  53. {# Returns true if definition is a boolean }
  54. function is_boolean(def : tdef) : boolean;
  55. {# Returns true if definition is a Pascal-style boolean (1 = true, zero = false) }
  56. function is_pasbool(def : tdef) : boolean;
  57. {# Returns true if definition is a C-style boolean (non-zero value = true, zero = false) }
  58. function is_cbool(def : tdef) : boolean;
  59. {# Returns true if definition is a char
  60. This excludes the unicode char.
  61. }
  62. function is_char(def : tdef) : boolean;
  63. {# Returns true if definition is a widechar }
  64. function is_widechar(def : tdef) : boolean;
  65. {# Returns true if definition is either an AnsiChar or a WideChar }
  66. function is_anychar(def : tdef) : boolean;
  67. {# Returns true if definition is a void}
  68. function is_void(def : tdef) : boolean;
  69. {# Returns true if definition is a smallset}
  70. function is_smallset(p : tdef) : boolean;
  71. {# Returns true, if def defines a signed data type
  72. (only for ordinal types)
  73. }
  74. function is_signed(def : tdef) : boolean;
  75. {# Returns an unsigned integer type of the same size as def; def must be
  76. an ordinal or enum }
  77. function get_unsigned_inttype(def: tdef): torddef;
  78. {# Returns whether def_from's range is comprised in def_to's if both are
  79. orddefs, false otherwise }
  80. function is_in_limit(def_from,def_to : tdef) : boolean;
  81. {# Returns whether def is reference counted }
  82. function is_managed_type(def: tdef) : boolean;{$ifdef USEINLINE}inline;{$endif}
  83. { # Returns whether def is needs to load RTTI for reference counting }
  84. function is_rtti_managed_type(def: tdef) : boolean;
  85. { function is_in_limit_value(val_from:TConstExprInt;def_from,def_to : tdef) : boolean;}
  86. {*****************************************************************************
  87. Array helper functions
  88. *****************************************************************************}
  89. {# Returns true, if p points to a zero based (non special like open or
  90. dynamic array def).
  91. This is mainly used to see if the array
  92. is convertable to a pointer
  93. }
  94. function is_zero_based_array(p : tdef) : boolean;
  95. {# Returns true if p points to an open array definition }
  96. function is_open_array(p : tdef) : boolean;
  97. {# Returns true if p points to a dynamic array definition }
  98. function is_dynamic_array(p : tdef) : boolean;
  99. {# Returns true, if p points to an array of const definition }
  100. function is_array_constructor(p : tdef) : boolean;
  101. {# Returns true, if p points to a variant array }
  102. function is_variant_array(p : tdef) : boolean;
  103. {# Returns true, if p points to an array of const }
  104. function is_array_of_const(p : tdef) : boolean;
  105. {# Returns true if p is an arraydef that describes a constant string }
  106. function is_conststring_array(p : tdef) : boolean;
  107. {# Returns true, if p points any kind of special array
  108. That is if the array is an open array, a variant
  109. array, an array constants constructor, or an
  110. array of const.
  111. Bitpacked arrays aren't special in this regard though.
  112. }
  113. function is_special_array(p : tdef) : boolean;
  114. {# Returns true, if p points to a normal array, bitpacked arrays are included }
  115. function is_normal_array(p : tdef) : boolean;
  116. {# Returns true if p is a bitpacked array }
  117. function is_packed_array(p: tdef) : boolean;
  118. {# Returns true if p is a bitpacked record }
  119. function is_packed_record_or_object(p: tdef) : boolean;
  120. {# Returns true if p is a char array def }
  121. function is_chararray(p : tdef) : boolean;
  122. {# Returns true if p is a wide char array def }
  123. function is_widechararray(p : tdef) : boolean;
  124. {# Returns true if p is a open char array def }
  125. function is_open_chararray(p : tdef) : boolean;
  126. {# Returns true if p is a open wide char array def }
  127. function is_open_widechararray(p : tdef) : boolean;
  128. {*****************************************************************************
  129. String helper functions
  130. *****************************************************************************}
  131. {# Returns true if p points to an open string type }
  132. function is_open_string(p : tdef) : boolean;
  133. {# Returns true if p is an ansi string type }
  134. function is_ansistring(p : tdef) : boolean;
  135. {# Returns true if p is an ansi string type with codepage 0 }
  136. function is_rawbytestring(p : tdef) : boolean;
  137. {# Returns true if p is a long string type }
  138. function is_longstring(p : tdef) : boolean;
  139. {# returns true if p is a wide string type }
  140. function is_widestring(p : tdef) : boolean;
  141. {# true if p is an unicode string def }
  142. function is_unicodestring(p : tdef) : boolean;
  143. {# true if p is an unicode/wide/ansistring string def }
  144. function is_dynamicstring(p : tdef) : boolean;
  145. {# returns true if p is a wide or unicode string type }
  146. function is_wide_or_unicode_string(p : tdef) : boolean;
  147. {# Returns true if p is a short string type }
  148. function is_shortstring(p : tdef) : boolean;
  149. {# Returns true if p is any pointer def }
  150. function is_pointer(p : tdef) : boolean;
  151. {# Returns true if p is a pchar def }
  152. function is_pchar(p : tdef) : boolean;
  153. {# Returns true if p is a pwidechar def }
  154. function is_pwidechar(p : tdef) : boolean;
  155. {# Returns true if p is a voidpointer def }
  156. function is_voidpointer(p : tdef) : boolean;
  157. {# Returns true, if definition is a float }
  158. function is_fpu(def : tdef) : boolean;
  159. {# Returns true, if def is a currency type }
  160. function is_currency(def : tdef) : boolean;
  161. {# Returns true, if def is a comp type (handled by the fpu) }
  162. function is_fpucomp(def : tdef) : boolean;
  163. {# Returns true, if def is a single type }
  164. function is_single(def : tdef) : boolean;
  165. {# Returns true, if def is a double type }
  166. function is_double(def : tdef) : boolean;
  167. {# Returns true, if def is an extended type }
  168. function is_extended(def : tdef) : boolean;
  169. {# Returns true, if definition is a "real" real (i.e. single/double/extended) }
  170. function is_real(def : tdef) : boolean;
  171. {# Returns true for single,double,extended and cextended }
  172. function is_real_or_cextended(def : tdef) : boolean;
  173. { true, if def is a 8 bit int type }
  174. function is_8bitint(def : tdef) : boolean;
  175. { true, if def is a 8 bit ordinal type }
  176. function is_8bit(def : tdef) : boolean;
  177. { true, if def is a 16 bit int type }
  178. function is_16bitint(def : tdef) : boolean;
  179. { true, if def is a 16 bit ordinal type }
  180. function is_16bit(def : tdef) : boolean;
  181. {# Returns true, if def is a 32 bit integer type }
  182. function is_32bitint(def : tdef) : boolean;
  183. {# Returns true, if def is a 32 bit ordinal type }
  184. function is_32bit(def : tdef) : boolean;
  185. {# Returns true, if def is a 64 bit integer type }
  186. function is_64bitint(def : tdef) : boolean;
  187. {# Returns true, if def is a 64 bit signed integer type }
  188. function is_s64bitint(def : tdef) : boolean;
  189. {# Returns true, if def is a 64 bit ordinal type }
  190. function is_64bit(def : tdef) : boolean;
  191. { returns true, if def is a longint type }
  192. function is_s32bitint(def : tdef) : boolean;
  193. { returns true, if def is a dword type }
  194. function is_u32bitint(def : tdef) : boolean;
  195. { true, if def1 and def2 are both integers of the same bit size and sign }
  196. function are_equal_ints(def1, def2: tdef): boolean;
  197. { true, if def is an int type, larger than the processor's native int size }
  198. function is_oversizedint(def : tdef) : boolean;
  199. { true, if def is an ordinal type, larger than the processor's native int size }
  200. function is_oversizedord(def : tdef) : boolean;
  201. { true, if def is an int type, equal in size to the processor's native int size }
  202. function is_nativeint(def : tdef) : boolean;
  203. { true, if def is an ordinal type, equal in size to the processor's native int size }
  204. function is_nativeord(def : tdef) : boolean;
  205. { true, if def is an unsigned int type, equal in size to the processor's native int size }
  206. function is_nativeuint(def : tdef) : boolean;
  207. { true, if def is a signed int type, equal in size to the processor's native int size }
  208. function is_nativesint(def : tdef) : boolean;
  209. type
  210. tperformrangecheck = (
  211. rc_internal, { nothing, internal conversion }
  212. rc_explicit, { no, but this is an explcit user conversion and hence can still give warnings in some cases (or errors in case of enums) }
  213. rc_implicit, { no, but this is an implicit conversion and hence can still give warnings/errors in some cases }
  214. rc_yes { yes }
  215. );
  216. {# If @var(l) isn't in the range of todef a range check error (if not explicit) is generated and
  217. the value is placed within the range
  218. }
  219. procedure adaptrange(todef : tdef;var l : tconstexprint; rangecheck: tperformrangecheck);
  220. { for when used with nf_explicit/nf_internal/cs_check_range nodeflags }
  221. procedure adaptrange(todef : tdef;var l : tconstexprint; internal, explicit, rangecheckstate: boolean);
  222. {# Returns the range of def, where @var(l) is the low-range and @var(h) is
  223. the high-range.
  224. }
  225. procedure getrange(def : tdef;out l, h : TConstExprInt);
  226. procedure getrangedefmasksize(def: tdef; out rangedef: tdef; out mask: TConstExprInt; out size: longint);
  227. { Returns the range type of an ordinal type in the sense of ISO-10206 }
  228. function get_iso_range_type(def: tdef): tdef;
  229. { type being a vector? }
  230. function is_vector(p : tdef) : boolean;
  231. { some type helper routines for MMX support }
  232. function is_mmx_able_array(p : tdef) : boolean;
  233. {# returns the mmx type }
  234. function mmx_type(p : tdef) : tmmxtype;
  235. { returns if the passed type (array) fits into an mm register }
  236. function fits_in_mm_register(p : tdef) : boolean;
  237. {# From a definition return the abstract code generator size enum. It is
  238. to note that the value returned can be @var(OS_NO) }
  239. function def_cgsize(def: tdef): tcgsize;
  240. { #Return an orddef (integer) correspondig to a tcgsize }
  241. function cgsize_orddef(size: tcgsize): torddef;
  242. {# Same as def_cgsize, except that it will interpret certain arrays as
  243. vectors and return OS_M* sizes for them }
  244. function def_cgmmsize(def: tdef): tcgsize;
  245. {# returns true, if the type passed is can be used with windows automation }
  246. function is_automatable(p : tdef) : boolean;
  247. { # returns true if the procdef has no parameters and no specified return type }
  248. function is_bareprocdef(pd : tprocdef): boolean;
  249. { returns true if the procdef is a C-style variadic function }
  250. function is_c_variadic(pd: tabstractprocdef): boolean; {$ifdef USEINLINE}inline;{$endif}
  251. { # returns the smallest base integer type whose range encompasses that of
  252. both ld and rd; if keep_sign_if_equal, then if ld and rd have the same
  253. signdness, the result will also get that signdness }
  254. function get_common_intdef(ld, rd: torddef; keep_sign_if_equal: boolean): torddef;
  255. { # calculates "not v" based on the provided def; returns true if the def
  256. was negatable, false otherwise }
  257. function calc_not_ordvalue(var v:Tconstexprint; var def:tdef):boolean;
  258. { # returns whether the type is potentially a valid type of/for an "univ" parameter
  259. (basically: it must have a compile-time size) }
  260. function is_valid_univ_para_type(def: tdef): boolean;
  261. { # returns whether the procdef/procvardef represents a nested procedure
  262. or not }
  263. function is_nested_pd(def: tabstractprocdef): boolean;{$ifdef USEINLINE}inline;{$endif}
  264. { # returns whether def is a type parameter of a generic }
  265. function is_typeparam(def : tdef) : boolean;{$ifdef USEINLINE}inline;{$endif}
  266. { returns true of def is a methodpointer }
  267. function is_methodpointer(def : tdef) : boolean;
  268. { returns true if def is a C "block" }
  269. function is_block(def: tdef): boolean;
  270. { returns the TTypeKind value of the def }
  271. function get_typekind(def: tdef): byte;
  272. implementation
  273. uses
  274. verbose,cutils,
  275. cpuinfo;
  276. { returns true, if def uses FPU }
  277. function is_fpu(def : tdef) : boolean;
  278. begin
  279. is_fpu:=(def.typ=floatdef);
  280. end;
  281. { returns true, if def is a currency type }
  282. function is_currency(def : tdef) : boolean;
  283. begin
  284. case s64currencytype.typ of
  285. orddef :
  286. result:=(def.typ=orddef) and
  287. (torddef(s64currencytype).ordtype=torddef(def).ordtype);
  288. floatdef :
  289. result:=(def.typ=floatdef) and
  290. (tfloatdef(s64currencytype).floattype=tfloatdef(def).floattype);
  291. else
  292. internalerror(200304222);
  293. end;
  294. end;
  295. function is_fpucomp(def: tdef): boolean;
  296. begin
  297. result:=(def.typ=floatdef) and
  298. (tfloatdef(def).floattype=s64comp);
  299. end;
  300. { returns true, if def is a single type }
  301. function is_single(def : tdef) : boolean;
  302. begin
  303. result:=(def.typ=floatdef) and
  304. (tfloatdef(def).floattype=s32real);
  305. end;
  306. { returns true, if def is a double type }
  307. function is_double(def : tdef) : boolean;
  308. begin
  309. result:=(def.typ=floatdef) and
  310. (tfloatdef(def).floattype=s64real);
  311. end;
  312. function is_extended(def : tdef) : boolean;
  313. begin
  314. result:=(def.typ=floatdef) and
  315. (tfloatdef(def).floattype in [s80real,sc80real]);
  316. end;
  317. { returns true, if definition is a "real" real (i.e. single/double/extended) }
  318. function is_real(def : tdef) : boolean;
  319. begin
  320. result:=(def.typ=floatdef) and
  321. (tfloatdef(def).floattype in [s32real,s64real,s80real]);
  322. end;
  323. function is_real_or_cextended(def: tdef): boolean;
  324. begin
  325. result:=(def.typ=floatdef) and
  326. (tfloatdef(def).floattype in [s32real,s64real,s80real,sc80real]);
  327. end;
  328. function range_to_basetype(const l,h:TConstExprInt):tordtype;
  329. begin
  330. { prefer signed over unsigned }
  331. if (l>=int64(-128)) and (h<=127) then
  332. range_to_basetype:=s8bit
  333. else if (l>=0) and (h<=255) then
  334. range_to_basetype:=u8bit
  335. else if (l>=int64(-32768)) and (h<=32767) then
  336. range_to_basetype:=s16bit
  337. else if (l>=0) and (h<=65535) then
  338. range_to_basetype:=u16bit
  339. else if (l>=int64(low(longint))) and (h<=high(longint)) then
  340. range_to_basetype:=s32bit
  341. else if (l>=low(cardinal)) and (h<=high(cardinal)) then
  342. range_to_basetype:=u32bit
  343. else if (l>=low(int64)) and (h<=high(int64)) then
  344. range_to_basetype:=s64bit
  345. else
  346. range_to_basetype:=u64bit;
  347. end;
  348. procedure range_to_type(const l,h:TConstExprInt;var def:tdef);
  349. begin
  350. { prefer signed over unsigned }
  351. if (l>=int64(-128)) and (h<=127) then
  352. def:=s8inttype
  353. else if (l>=0) and (h<=255) then
  354. def:=u8inttype
  355. else if (l>=int64(-32768)) and (h<=32767) then
  356. def:=s16inttype
  357. else if (l>=0) and (h<=65535) then
  358. def:=u16inttype
  359. else if (l>=int64(low(longint))) and (h<=high(longint)) then
  360. def:=s32inttype
  361. else if (l>=low(cardinal)) and (h<=high(cardinal)) then
  362. def:=u32inttype
  363. else if (l>=low(int64)) and (h<=high(int64)) then
  364. def:=s64inttype
  365. else
  366. def:=u64inttype;
  367. end;
  368. procedure int_to_type(const v:TConstExprInt;var def:tdef);
  369. begin
  370. range_to_type(v,v,def);
  371. end;
  372. { true if p is an ordinal }
  373. function is_ordinal(def : tdef) : boolean;
  374. var
  375. dt : tordtype;
  376. begin
  377. case def.typ of
  378. orddef :
  379. begin
  380. dt:=torddef(def).ordtype;
  381. is_ordinal:=dt in [uchar,uwidechar,
  382. u8bit,u16bit,u32bit,u64bit,
  383. s8bit,s16bit,s32bit,s64bit,
  384. pasbool1,pasbool8,pasbool16,pasbool32,pasbool64,
  385. bool8bit,bool16bit,bool32bit,bool64bit,customint];
  386. end;
  387. enumdef :
  388. is_ordinal:=true;
  389. else
  390. is_ordinal:=false;
  391. end;
  392. end;
  393. { true if p is a string }
  394. function is_string(def : tdef) : boolean;
  395. begin
  396. is_string := (assigned(def) and (def.typ = stringdef));
  397. end;
  398. function is_stringlike(def : tdef) : boolean;
  399. begin
  400. result := is_string(def) or
  401. is_anychar(def) or
  402. is_pchar(def) or
  403. is_pwidechar(def) or
  404. is_chararray(def) or
  405. is_widechararray(def) or
  406. is_open_chararray(def) or
  407. is_open_widechararray(def) or
  408. (def=java_jlstring);
  409. end;
  410. function is_enum(def : tdef) : boolean;
  411. begin
  412. result:=def.typ=enumdef;
  413. end;
  414. function is_set(def : tdef) : boolean;
  415. begin
  416. result:=def.typ=setdef;
  417. end;
  418. { returns the min. value of the type }
  419. function get_min_value(def : tdef) : TConstExprInt;
  420. begin
  421. case def.typ of
  422. orddef:
  423. result:=torddef(def).low;
  424. enumdef:
  425. result:=int64(tenumdef(def).min);
  426. else
  427. result:=0;
  428. end;
  429. end;
  430. { returns the max. value of the type }
  431. function get_max_value(def : tdef) : TConstExprInt;
  432. begin
  433. case def.typ of
  434. orddef:
  435. result:=torddef(def).high;
  436. enumdef:
  437. result:=tenumdef(def).max;
  438. else
  439. result:=0;
  440. end;
  441. end;
  442. function spans_entire_range(def: tdef): boolean;
  443. var
  444. lv, hv: Tconstexprint;
  445. mask: qword;
  446. size: longint;
  447. begin
  448. case def.typ of
  449. orddef,
  450. enumdef:
  451. getrange(def,lv,hv);
  452. else
  453. internalerror(2019062203);
  454. end;
  455. size:=def.size;
  456. case size of
  457. 1: mask:=$ff;
  458. 2: mask:=$ffff;
  459. 4: mask:=$ffffffff;
  460. 8: mask:=qword(-1);
  461. else
  462. internalerror(2019062204);
  463. end;
  464. result:=false;
  465. if is_signed(def) then
  466. begin
  467. if (lv.uvalue and mask)<>(qword(1) shl (size*8-1)) then
  468. exit;
  469. if (hv.uvalue and mask)<>(mask shr 1) then
  470. exit;
  471. end
  472. else
  473. begin
  474. if lv<>0 then
  475. exit;
  476. if hv.uvalue<>mask then
  477. exit;
  478. end;
  479. result:=true;
  480. end;
  481. { true if p is an integer }
  482. function is_integer(def : tdef) : boolean;
  483. begin
  484. result:=(def.typ=orddef) and
  485. (torddef(def).ordtype in [u8bit,u16bit,u32bit,u64bit,
  486. s8bit,s16bit,s32bit,s64bit,
  487. customint]);
  488. end;
  489. { true if p is a boolean }
  490. function is_boolean(def : tdef) : boolean;
  491. begin
  492. result:=(def.typ=orddef) and
  493. (torddef(def).ordtype in [pasbool1,pasbool8,pasbool16,pasbool32,pasbool64,bool8bit,bool16bit,bool32bit,bool64bit]);
  494. end;
  495. function is_pasbool(def : tdef) : boolean;
  496. begin
  497. result:=(def.typ=orddef) and
  498. (torddef(def).ordtype in [pasbool1,pasbool8,pasbool16,pasbool32,pasbool64]);
  499. end;
  500. { true if def is a C-style boolean (non-zero value = true, zero = false) }
  501. function is_cbool(def : tdef) : boolean;
  502. begin
  503. result:=(def.typ=orddef) and
  504. (torddef(def).ordtype in [bool8bit,bool16bit,bool32bit,bool64bit]);
  505. end;
  506. { true if p is a void }
  507. function is_void(def : tdef) : boolean;
  508. begin
  509. result:=(def.typ=orddef) and
  510. (torddef(def).ordtype=uvoid);
  511. end;
  512. { true if p is a char }
  513. function is_char(def : tdef) : boolean;
  514. begin
  515. result:=(def.typ=orddef) and
  516. (torddef(def).ordtype=uchar);
  517. end;
  518. { true if p is a wchar }
  519. function is_widechar(def : tdef) : boolean;
  520. begin
  521. result:=(def.typ=orddef) and
  522. (torddef(def).ordtype=uwidechar);
  523. end;
  524. { true if p is a char or wchar }
  525. function is_anychar(def : tdef) : boolean;
  526. begin
  527. result:=(def.typ=orddef) and
  528. (torddef(def).ordtype in [uchar,uwidechar])
  529. end;
  530. { true if p is signed (integer) }
  531. function is_signed(def : tdef) : boolean;
  532. begin
  533. case def.typ of
  534. orddef :
  535. result:=torddef(def).low < 0;
  536. enumdef :
  537. result:=tenumdef(def).min < 0;
  538. arraydef :
  539. result:=is_signed(tarraydef(def).rangedef);
  540. else
  541. result:=false;
  542. end;
  543. end;
  544. function get_unsigned_inttype(def: tdef): torddef;
  545. begin
  546. case def.typ of
  547. orddef,
  548. enumdef:
  549. result:=cgsize_orddef(tcgsize2unsigned[def_cgsize(def)]);
  550. else
  551. internalerror(2016062001);
  552. end;
  553. end;
  554. function is_in_limit(def_from,def_to : tdef) : boolean;
  555. begin
  556. if (def_from.typ<>def_to.typ) or
  557. not(def_from.typ in [orddef,enumdef,setdef]) then
  558. begin
  559. is_in_limit := false;
  560. exit;
  561. end;
  562. case def_from.typ of
  563. orddef:
  564. is_in_limit:=(torddef(def_from).low>=torddef(def_to).low) and
  565. (torddef(def_from).high<=torddef(def_to).high);
  566. enumdef:
  567. is_in_limit:=(tenumdef(def_from).min>=tenumdef(def_to).min) and
  568. (tenumdef(def_from).max<=tenumdef(def_to).max);
  569. setdef:
  570. is_in_limit:=(tsetdef(def_from).setbase>=tsetdef(def_to).setbase) and
  571. (tsetdef(def_from).setmax<=tsetdef(def_to).setmax);
  572. else
  573. is_in_limit:=false;
  574. end;
  575. end;
  576. function is_managed_type(def: tdef): boolean;{$ifdef USEINLINE}inline;{$endif}
  577. begin
  578. result:=def.needs_inittable;
  579. end;
  580. function is_rtti_managed_type(def: tdef): boolean;
  581. begin
  582. result:=def.needs_inittable and not (
  583. is_interfacecom_or_dispinterface(def) or
  584. (def.typ=variantdef) or
  585. (
  586. (def.typ=stringdef) and
  587. (tstringdef(def).stringtype in [st_ansistring,st_widestring,st_unicodestring])
  588. )
  589. );
  590. end;
  591. { true, if p points to an open array def }
  592. function is_open_string(p : tdef) : boolean;
  593. begin
  594. is_open_string:=(p.typ=stringdef) and
  595. (tstringdef(p).stringtype=st_shortstring) and
  596. (tstringdef(p).len=0);
  597. end;
  598. { true, if p points to a zero based array def }
  599. function is_zero_based_array(p : tdef) : boolean;
  600. begin
  601. result:=(p.typ=arraydef) and
  602. (tarraydef(p).lowrange=0) and
  603. not(is_special_array(p));
  604. end;
  605. { true if p points to a dynamic array def }
  606. function is_dynamic_array(p : tdef) : boolean;
  607. begin
  608. result:=(p.typ=arraydef) and
  609. (ado_IsDynamicArray in tarraydef(p).arrayoptions);
  610. end;
  611. { true, if p points to an open array def }
  612. function is_open_array(p : tdef) : boolean;
  613. begin
  614. { check for sizesinttype is needed, because for unsigned the high
  615. range is also -1 ! (PFV) }
  616. result:=(p.typ=arraydef) and
  617. (tarraydef(p).rangedef=sizesinttype) and
  618. (ado_OpenArray in tarraydef(p).arrayoptions) and
  619. ((tarraydef(p).arrayoptions * [ado_IsVariant,ado_IsArrayOfConst,ado_IsConstructor,ado_IsDynamicArray])=[]);
  620. end;
  621. { true, if p points to an array of const def }
  622. function is_array_constructor(p : tdef) : boolean;
  623. begin
  624. result:=(p.typ=arraydef) and
  625. (ado_IsConstructor in tarraydef(p).arrayoptions);
  626. end;
  627. { true, if p points to a variant array }
  628. function is_variant_array(p : tdef) : boolean;
  629. begin
  630. result:=(p.typ=arraydef) and
  631. (ado_IsVariant in tarraydef(p).arrayoptions);
  632. end;
  633. { true, if p points to an array of const }
  634. function is_array_of_const(p : tdef) : boolean;
  635. begin
  636. result:=(p.typ=arraydef) and
  637. (ado_IsArrayOfConst in tarraydef(p).arrayoptions);
  638. end;
  639. function is_conststring_array(p: tdef): boolean;
  640. begin
  641. result:=(p.typ=arraydef) and
  642. (ado_IsConstString in tarraydef(p).arrayoptions);
  643. end;
  644. { true, if p points to a special array, bitpacked arrays aren't special in this regard though }
  645. function is_special_array(p : tdef) : boolean;
  646. begin
  647. result:=(p.typ=arraydef) and
  648. (
  649. ((tarraydef(p).arrayoptions * [ado_IsVariant,ado_IsArrayOfConst,ado_IsConstructor,ado_IsDynamicArray])<>[]) or
  650. is_open_array(p)
  651. );
  652. end;
  653. { true, if p points to a normal array, bitpacked arrays are included }
  654. function is_normal_array(p : tdef) : boolean;
  655. begin
  656. result:=(p.typ=arraydef) and
  657. ((tarraydef(p).arrayoptions * [ado_IsVariant,ado_IsArrayOfConst,ado_IsConstructor,ado_IsDynamicArray])=[]) and
  658. not(is_open_array(p));
  659. end;
  660. { true if p is an ansi string def }
  661. function is_ansistring(p : tdef) : boolean;
  662. begin
  663. is_ansistring:=(p.typ=stringdef) and
  664. (tstringdef(p).stringtype=st_ansistring);
  665. end;
  666. { true if p is an ansi string def with codepage CP_NONE }
  667. function is_rawbytestring(p : tdef) : boolean;
  668. begin
  669. is_rawbytestring:=(p.typ=stringdef) and
  670. (tstringdef(p).stringtype=st_ansistring) and
  671. (tstringdef(p).encoding=globals.CP_NONE);
  672. end;
  673. { true if p is an long string def }
  674. function is_longstring(p : tdef) : boolean;
  675. begin
  676. is_longstring:=(p.typ=stringdef) and
  677. (tstringdef(p).stringtype=st_longstring);
  678. end;
  679. { true if p is an wide string def }
  680. function is_widestring(p : tdef) : boolean;
  681. begin
  682. is_widestring:=(p.typ=stringdef) and
  683. (tstringdef(p).stringtype=st_widestring);
  684. end;
  685. function is_dynamicstring(p: tdef): boolean;
  686. begin
  687. is_dynamicstring:=(p.typ=stringdef) and
  688. (tstringdef(p).stringtype in [st_ansistring,st_widestring,st_unicodestring]);
  689. end;
  690. { true if p is an wide string def }
  691. function is_wide_or_unicode_string(p : tdef) : boolean;
  692. begin
  693. is_wide_or_unicode_string:=(p.typ=stringdef) and
  694. (tstringdef(p).stringtype in [st_widestring,st_unicodestring]);
  695. end;
  696. { true if p is an unicode string def }
  697. function is_unicodestring(p : tdef) : boolean;
  698. begin
  699. is_unicodestring:=(p.typ=stringdef) and
  700. (tstringdef(p).stringtype=st_unicodestring);
  701. end;
  702. { true if p is an short string def }
  703. function is_shortstring(p : tdef) : boolean;
  704. begin
  705. is_shortstring:=(p.typ=stringdef) and
  706. (tstringdef(p).stringtype=st_shortstring);
  707. end;
  708. { true if p is bit packed array def }
  709. function is_packed_array(p: tdef) : boolean;
  710. begin
  711. is_packed_array :=
  712. (p.typ = arraydef) and
  713. (ado_IsBitPacked in tarraydef(p).arrayoptions);
  714. end;
  715. { true if p is bit packed record def }
  716. function is_packed_record_or_object(p: tdef) : boolean;
  717. begin
  718. is_packed_record_or_object :=
  719. (p.typ in [recorddef,objectdef]) and
  720. (tabstractrecorddef(p).is_packed);
  721. end;
  722. { true if p is a char array def }
  723. function is_chararray(p : tdef) : boolean;
  724. begin
  725. is_chararray:=(p.typ=arraydef) and
  726. is_char(tarraydef(p).elementdef) and
  727. not(is_special_array(p));
  728. end;
  729. { true if p is a widechar array def }
  730. function is_widechararray(p : tdef) : boolean;
  731. begin
  732. is_widechararray:=(p.typ=arraydef) and
  733. is_widechar(tarraydef(p).elementdef) and
  734. not(is_special_array(p));
  735. end;
  736. { true if p is a open char array def }
  737. function is_open_chararray(p : tdef) : boolean;
  738. begin
  739. is_open_chararray:= is_open_array(p) and
  740. is_char(tarraydef(p).elementdef);
  741. end;
  742. { true if p is a open wide char array def }
  743. function is_open_widechararray(p : tdef) : boolean;
  744. begin
  745. is_open_widechararray:= is_open_array(p) and
  746. is_widechar(tarraydef(p).elementdef);
  747. end;
  748. { true if p is any pointer def }
  749. function is_pointer(p : tdef) : boolean;
  750. begin
  751. is_pointer:=(p.typ=pointerdef);
  752. end;
  753. { true if p is a pchar def }
  754. function is_pchar(p : tdef) : boolean;
  755. begin
  756. is_pchar:=(p.typ=pointerdef) and
  757. (is_char(tpointerdef(p).pointeddef) or
  758. (is_zero_based_array(tpointerdef(p).pointeddef) and
  759. is_chararray(tpointerdef(p).pointeddef)));
  760. end;
  761. { true if p is a pchar def }
  762. function is_pwidechar(p : tdef) : boolean;
  763. begin
  764. is_pwidechar:=(p.typ=pointerdef) and
  765. (is_widechar(tpointerdef(p).pointeddef) or
  766. (is_zero_based_array(tpointerdef(p).pointeddef) and
  767. is_widechararray(tpointerdef(p).pointeddef)));
  768. end;
  769. { true if p is a voidpointer def }
  770. function is_voidpointer(p : tdef) : boolean;
  771. begin
  772. is_voidpointer:=(p.typ=pointerdef) and
  773. (tpointerdef(p).pointeddef.typ=orddef) and
  774. (torddef(tpointerdef(p).pointeddef).ordtype=uvoid);
  775. end;
  776. { true, if def is a 8 bit int type }
  777. function is_8bitint(def : tdef) : boolean;
  778. begin
  779. result:=(def.typ=orddef) and (torddef(def).ordtype in [u8bit,s8bit])
  780. end;
  781. { true, if def is a 8 bit ordinal type }
  782. function is_8bit(def : tdef) : boolean;
  783. begin
  784. result:=(def.typ=orddef) and (torddef(def).ordtype in [u8bit,s8bit,pasbool1,pasbool8,bool8bit,uchar])
  785. end;
  786. { true, if def is a 16 bit int type }
  787. function is_16bitint(def : tdef) : boolean;
  788. begin
  789. result:=(def.typ=orddef) and (torddef(def).ordtype in [u16bit,s16bit])
  790. end;
  791. { true, if def is a 16 bit ordinal type }
  792. function is_16bit(def : tdef) : boolean;
  793. begin
  794. result:=(def.typ=orddef) and (torddef(def).ordtype in [u16bit,s16bit,pasbool16,bool16bit,uwidechar])
  795. end;
  796. { true, if def is a 32 bit int type }
  797. function is_32bitint(def : tdef) : boolean;
  798. begin
  799. result:=(def.typ=orddef) and (torddef(def).ordtype in [u32bit,s32bit])
  800. end;
  801. { true, if def is a 32 bit ordinal type }
  802. function is_32bit(def: tdef): boolean;
  803. begin
  804. result:=(def.typ=orddef) and (torddef(def).ordtype in [u32bit,s32bit,pasbool32,bool32bit])
  805. end;
  806. { true, if def is a 64 bit int type }
  807. function is_64bitint(def : tdef) : boolean;
  808. begin
  809. is_64bitint:=(def.typ=orddef) and (torddef(def).ordtype in [u64bit,s64bit])
  810. end;
  811. function is_s64bitint(def: tdef): boolean;
  812. begin
  813. is_s64bitint:=(def.typ=orddef) and (torddef(def).ordtype=s64bit)
  814. end;
  815. { true, if def is a 64 bit type }
  816. function is_64bit(def : tdef) : boolean;
  817. begin
  818. is_64bit:=(def.typ=orddef) and (torddef(def).ordtype in [u64bit,s64bit,scurrency,pasbool64,bool64bit])
  819. end;
  820. { returns true, if def is a longint type }
  821. function is_s32bitint(def : tdef) : boolean;
  822. begin
  823. result:=(def.typ=orddef) and
  824. (torddef(def).ordtype=s32bit);
  825. end;
  826. { returns true, if def is a dword type }
  827. function is_u32bitint(def : tdef) : boolean;
  828. begin
  829. result:=(def.typ=orddef) and
  830. (torddef(def).ordtype=u32bit);
  831. end;
  832. { true, if def1 and def2 are both integers of the same bit size and sign }
  833. function are_equal_ints(def1, def2: tdef): boolean;
  834. begin
  835. result:=(def1.typ=orddef) and (def2.typ=orddef) and
  836. (torddef(def1).ordtype in [u8bit,u16bit,u32bit,u64bit,
  837. s8bit,s16bit,s32bit,s64bit,customint]) and
  838. (torddef(def1).ordtype=torddef(def2).ordtype) and
  839. ((torddef(def1).ordtype<>customint) or
  840. ((torddef(def1).low=torddef(def2).low) and
  841. (torddef(def1).high=torddef(def2).high)));
  842. end;
  843. { true, if def is an int type, larger than the processor's native int size }
  844. function is_oversizedint(def : tdef) : boolean;
  845. begin
  846. {$if defined(cpu8bitalu)}
  847. result:=is_64bitint(def) or is_32bitint(def) or is_16bitint(def);
  848. {$elseif defined(cpu16bitalu)}
  849. result:=is_64bitint(def) or is_32bitint(def);
  850. {$elseif defined(cpu32bitaddr)}
  851. result:=is_64bitint(def);
  852. {$elseif defined(cpu64bitaddr)}
  853. result:=false;
  854. {$endif}
  855. end;
  856. { true, if def is an ordinal type, larger than the processor's native int size }
  857. function is_oversizedord(def : tdef) : boolean;
  858. begin
  859. {$if defined(cpu8bitalu)}
  860. result:=is_64bit(def) or is_32bit(def) or is_16bit(def);
  861. {$elseif defined(cpu16bitalu)}
  862. result:=is_64bit(def) or is_32bit(def);
  863. {$elseif defined(cpu32bitaddr)}
  864. result:=is_64bit(def);
  865. {$elseif defined(cpu64bitaddr)}
  866. result:=false;
  867. {$endif}
  868. end;
  869. { true, if def is an int type, equal in size to the processor's native int size }
  870. function is_nativeint(def: tdef): boolean;
  871. begin
  872. {$if defined(cpu8bitalu)}
  873. result:=is_8bitint(def);
  874. {$elseif defined(cpu16bitalu)}
  875. result:=is_16bitint(def);
  876. {$elseif defined(cpu32bitaddr)}
  877. result:=is_32bitint(def);
  878. {$elseif defined(cpu64bitaddr)}
  879. result:=is_64bitint(def);
  880. {$endif}
  881. end;
  882. { true, if def is an ordinal type, equal in size to the processor's native int size }
  883. function is_nativeord(def: tdef): boolean;
  884. begin
  885. {$if defined(cpu8bitalu)}
  886. result:=is_8bit(def);
  887. {$elseif defined(cpu16bitalu)}
  888. result:=is_16bit(def);
  889. {$elseif defined(cpu32bitaddr)}
  890. result:=is_32bit(def);
  891. {$elseif defined(cpu64bitaddr)}
  892. result:=is_64bit(def);
  893. {$endif}
  894. end;
  895. { true, if def is an unsigned int type, equal in size to the processor's native int size }
  896. function is_nativeuint(def: tdef): boolean;
  897. begin
  898. result:=is_nativeint(def) and (def.typ=orddef) and (torddef(def).ordtype in [u64bit,u32bit,u16bit,u8bit]);
  899. end;
  900. { true, if def is a signed int type, equal in size to the processor's native int size }
  901. function is_nativesint(def: tdef): boolean;
  902. begin
  903. result:=is_nativeint(def) and (def.typ=orddef) and (torddef(def).ordtype in [s64bit,s32bit,s16bit,s8bit]);
  904. end;
  905. { if l isn't in the range of todef a range check error (if not explicit) is generated and
  906. the value is placed within the range }
  907. procedure adaptrange(todef : tdef;var l : tconstexprint; rangecheck: tperformrangecheck);
  908. var
  909. lv,hv,oldval,sextval,mask: TConstExprInt;
  910. rangedef: tdef;
  911. rangedefsize: longint;
  912. warned: boolean;
  913. begin
  914. getrange(todef,lv,hv);
  915. if (l<lv) or (l>hv) then
  916. begin
  917. warned:=false;
  918. if rangecheck in [rc_implicit,rc_yes] then
  919. begin
  920. if (rangecheck=rc_yes) or
  921. (todef.typ=enumdef) then
  922. Message3(type_e_range_check_error_bounds,tostr(l),tostr(lv),tostr(hv))
  923. else
  924. Message3(type_w_range_check_error_bounds,tostr(l),tostr(lv),tostr(hv));
  925. warned:=true;
  926. end
  927. { give warnings about range errors with explicit typeconversions if the target
  928. type does not span the entire range that can be represented by its bits
  929. (subrange type or enum), because then the result is undefined }
  930. else if (rangecheck<>rc_internal) and
  931. (not is_pasbool(todef) and
  932. not spans_entire_range(todef)) then
  933. begin
  934. Message3(type_w_range_check_error_bounds,tostr(l),tostr(lv),tostr(hv));
  935. warned:=true;
  936. end;
  937. { Fix the value to fit in the allocated space for this type of variable }
  938. oldval:=l;
  939. getrangedefmasksize(todef,rangedef,mask,rangedefsize);
  940. l:=l and mask;
  941. {reset sign, i.e. converting -1 to qword changes the value to high(qword)}
  942. l.signed:=false;
  943. sextval:=0;
  944. { do sign extension if necessary (JM) }
  945. case rangedefsize of
  946. 1: sextval.svalue:=shortint(l.svalue);
  947. 2: sextval.svalue:=smallint(l.svalue);
  948. 4: sextval.svalue:=longint(l.svalue);
  949. 8: sextval.svalue:=l.svalue;
  950. else
  951. internalerror(201906230);
  952. end;
  953. sextval.signed:=true;
  954. { Detect if the type spans the entire range, but more bits were specified than
  955. the type can contain, e.g. shortint($fff).
  956. However, none of the following should result in a warning:
  957. 1) shortint($ff) (-> $ff -> $ff -> $ffff ffff ffff ffff)
  958. 2) shortint(longint(-1)) ($ffff ffff ffff ffff ffff -> $ff -> $ffff ffff ffff ffff
  959. 3) cardinal(-1) (-> $ffff ffff ffff ffff -> $ffff ffff)
  960. }
  961. if not warned and
  962. (rangecheck<>rc_internal) and
  963. (oldval.uvalue<>l.uvalue) and
  964. (oldval.uvalue<>sextval.uvalue) then
  965. begin
  966. Message3(type_w_range_check_error_bounds,tostr(oldval),tostr(lv),tostr(hv));
  967. end;
  968. if is_signed(rangedef) then
  969. l:=sextval;
  970. end;
  971. end;
  972. procedure adaptrange(todef: tdef; var l: tconstexprint; internal, explicit, rangecheckstate: boolean);
  973. begin
  974. if internal then
  975. adaptrange(todef, l, rc_internal)
  976. else if explicit then
  977. adaptrange(todef, l, rc_explicit)
  978. else if not rangecheckstate then
  979. adaptrange(todef, l, rc_implicit)
  980. else
  981. adaptrange(todef, l, rc_yes)
  982. end;
  983. { return the range from def in l and h }
  984. procedure getrange(def : tdef;out l, h : TConstExprInt);
  985. begin
  986. case def.typ of
  987. orddef :
  988. begin
  989. l:=torddef(def).low;
  990. h:=torddef(def).high;
  991. end;
  992. enumdef :
  993. begin
  994. l:=int64(tenumdef(def).min);
  995. h:=int64(tenumdef(def).max);
  996. end;
  997. arraydef :
  998. begin
  999. l:=int64(tarraydef(def).lowrange);
  1000. h:=int64(tarraydef(def).highrange);
  1001. end;
  1002. undefineddef:
  1003. begin
  1004. l:=torddef(sizesinttype).low;
  1005. h:=torddef(sizesinttype).high;
  1006. end;
  1007. else
  1008. internalerror(200611054);
  1009. end;
  1010. end;
  1011. procedure getrangedefmasksize(def: tdef; out rangedef: tdef; out mask: TConstExprInt; out size: longint);
  1012. begin
  1013. case def.typ of
  1014. orddef, enumdef:
  1015. begin
  1016. rangedef:=def;
  1017. size:=def.size;
  1018. case size of
  1019. 1: mask:=$ff;
  1020. 2: mask:=$ffff;
  1021. 4: mask:=$ffffffff;
  1022. 8: mask:=$ffffffffffffffff;
  1023. else
  1024. internalerror(2019062305);
  1025. end;
  1026. end;
  1027. arraydef:
  1028. begin
  1029. rangedef:=tarraydef(def).rangedef;
  1030. getrangedefmasksize(rangedef,rangedef,mask,size);
  1031. end;
  1032. undefineddef:
  1033. begin
  1034. rangedef:=sizesinttype;
  1035. size:=rangedef.size;
  1036. mask:=-1;
  1037. end;
  1038. else
  1039. internalerror(2019062306);
  1040. end;
  1041. end;
  1042. function mmx_type(p : tdef) : tmmxtype;
  1043. begin
  1044. mmx_type:=mmxno;
  1045. if is_mmx_able_array(p) then
  1046. begin
  1047. if tarraydef(p).elementdef.typ=floatdef then
  1048. case tfloatdef(tarraydef(p).elementdef).floattype of
  1049. s32real:
  1050. mmx_type:=mmxsingle;
  1051. else
  1052. ;
  1053. end
  1054. else
  1055. case torddef(tarraydef(p).elementdef).ordtype of
  1056. u8bit:
  1057. mmx_type:=mmxu8bit;
  1058. s8bit:
  1059. mmx_type:=mmxs8bit;
  1060. u16bit:
  1061. mmx_type:=mmxu16bit;
  1062. s16bit:
  1063. mmx_type:=mmxs16bit;
  1064. u32bit:
  1065. mmx_type:=mmxu32bit;
  1066. s32bit:
  1067. mmx_type:=mmxs32bit;
  1068. else
  1069. ;
  1070. end;
  1071. end;
  1072. end;
  1073. { The range-type of an ordinal-type that is a subrange-type shall be the host-type (see 6.4.2.4) of the subrange-type.
  1074. The range-type of an ordinal-type that is not a subrange-type shall be the ordinal-type.
  1075. The subrange-bounds shall be of compatible ordinal-types, and the range-type (see 6.4.2.1) of the ordinal-types shall
  1076. be designated the host-type of the subrange-type. }
  1077. function get_iso_range_type(def: tdef): tdef;
  1078. begin
  1079. result:=nil;
  1080. case def.typ of
  1081. orddef:
  1082. begin
  1083. if is_integer(def) then
  1084. begin
  1085. if (torddef(def).low>=torddef(sinttype).low) and
  1086. (torddef(def).high<=torddef(sinttype).high) then
  1087. result:=sinttype
  1088. else
  1089. range_to_type(torddef(def).low,torddef(def).high,result);
  1090. end
  1091. else case torddef(def).ordtype of
  1092. pasbool1:
  1093. result:=pasbool1type;
  1094. pasbool8:
  1095. result:=pasbool8type;
  1096. pasbool16:
  1097. result:=pasbool16type;
  1098. pasbool32:
  1099. result:=pasbool32type;
  1100. pasbool64:
  1101. result:=pasbool64type;
  1102. bool8bit:
  1103. result:=bool8type;
  1104. bool16bit:
  1105. result:=bool16type;
  1106. bool32bit:
  1107. result:=bool32type;
  1108. bool64bit:
  1109. result:=bool64type;
  1110. uchar:
  1111. result:=cansichartype;
  1112. uwidechar:
  1113. result:=cwidechartype;
  1114. scurrency:
  1115. result:=s64currencytype;
  1116. else
  1117. internalerror(2018010901);
  1118. end;
  1119. end;
  1120. enumdef:
  1121. begin
  1122. while assigned(tenumdef(def).basedef) do
  1123. def:=tenumdef(def).basedef;
  1124. result:=def;
  1125. end
  1126. else
  1127. internalerror(2018010701);
  1128. end;
  1129. end;
  1130. function is_vector(p : tdef) : boolean;
  1131. begin
  1132. result:=(p.typ=arraydef) and
  1133. not(is_special_array(p)) and
  1134. (tarraydef(p).elementdef.typ in [floatdef,orddef]) {and
  1135. (tarraydef(p).elementdef.typ=floatdef) and
  1136. (tfloatdef(tarraydef(p).elementdef).floattype in [s32real,s64real])};
  1137. end;
  1138. { returns if the passed type (array) fits into an mm register }
  1139. function fits_in_mm_register(p : tdef) : boolean;
  1140. begin
  1141. {$ifdef x86}
  1142. result:= is_vector(p) and
  1143. (
  1144. (
  1145. (tarraydef(p).elementdef.typ=floatdef) and
  1146. (
  1147. (tarraydef(p).lowrange=0) and
  1148. ((tarraydef(p).highrange=3) or
  1149. (UseAVX and (tarraydef(p).highrange=7)) or
  1150. (UseAVX512 and (tarraydef(p).highrange=15))
  1151. ) and
  1152. (tfloatdef(tarraydef(p).elementdef).floattype=s32real)
  1153. )
  1154. ) or
  1155. (
  1156. (tarraydef(p).elementdef.typ=floatdef) and
  1157. (
  1158. (tarraydef(p).lowrange=0) and
  1159. ((tarraydef(p).highrange=1) or
  1160. (UseAVX and (tarraydef(p).highrange=3)) or
  1161. (UseAVX512 and (tarraydef(p).highrange=7))
  1162. )and
  1163. (tfloatdef(tarraydef(p).elementdef).floattype=s64real)
  1164. )
  1165. ) {or
  1166. // MMX registers
  1167. (
  1168. (tarraydef(p).elementdef.typ=floatdef) and
  1169. (
  1170. (tarraydef(p).lowrange=0) and
  1171. (tarraydef(p).highrange=1) and
  1172. (tfloatdef(tarraydef(p).elementdef).floattype=s32real)
  1173. )
  1174. ) or
  1175. (
  1176. (tarraydef(p).elementdef.typ=orddef) and
  1177. (
  1178. (tarraydef(p).lowrange=0) and
  1179. (tarraydef(p).highrange=1) and
  1180. (torddef(tarraydef(p).elementdef).ordtype in [s32bit,u32bit])
  1181. )
  1182. ) or
  1183. (
  1184. (tarraydef(p).elementdef.typ=orddef) and
  1185. (
  1186. (tarraydef(p).lowrange=0) and
  1187. (tarraydef(p).highrange=3) and
  1188. (torddef(tarraydef(p).elementdef).ordtype in [s16bit,u16bit])
  1189. )
  1190. ) or
  1191. (
  1192. (tarraydef(p).elementdef.typ=orddef) and
  1193. (
  1194. (tarraydef(p).lowrange=0) and
  1195. (tarraydef(p).highrange=7) and
  1196. (torddef(tarraydef(p).elementdef).ordtype in [s8bit,u8bit])
  1197. )
  1198. ) }
  1199. );
  1200. {$else x86}
  1201. result:=false;
  1202. {$endif x86}
  1203. end;
  1204. function is_mmx_able_array(p : tdef) : boolean;
  1205. begin
  1206. {$ifdef SUPPORT_MMX}
  1207. if (cs_mmx_saturation in current_settings.localswitches) then
  1208. begin
  1209. is_mmx_able_array:=(p.typ=arraydef) and
  1210. not(is_special_array(p)) and
  1211. (
  1212. (
  1213. (tarraydef(p).elementdef.typ=orddef) and
  1214. (
  1215. (
  1216. (tarraydef(p).lowrange=0) and
  1217. (tarraydef(p).highrange=1) and
  1218. (torddef(tarraydef(p).elementdef).ordtype in [u32bit,s32bit])
  1219. )
  1220. or
  1221. (
  1222. (tarraydef(p).lowrange=0) and
  1223. (tarraydef(p).highrange=3) and
  1224. (torddef(tarraydef(p).elementdef).ordtype in [u16bit,s16bit])
  1225. )
  1226. )
  1227. )
  1228. or
  1229. (
  1230. (
  1231. (tarraydef(p).elementdef.typ=floatdef) and
  1232. (
  1233. (tarraydef(p).lowrange=0) and
  1234. (tarraydef(p).highrange=1) and
  1235. (tfloatdef(tarraydef(p).elementdef).floattype=s32real)
  1236. )
  1237. )
  1238. )
  1239. );
  1240. end
  1241. else
  1242. begin
  1243. is_mmx_able_array:=(p.typ=arraydef) and
  1244. (
  1245. (
  1246. (tarraydef(p).elementdef.typ=orddef) and
  1247. (
  1248. (
  1249. (tarraydef(p).lowrange=0) and
  1250. (tarraydef(p).highrange=1) and
  1251. (torddef(tarraydef(p).elementdef).ordtype in [u32bit,s32bit])
  1252. )
  1253. or
  1254. (
  1255. (tarraydef(p).lowrange=0) and
  1256. (tarraydef(p).highrange=3) and
  1257. (torddef(tarraydef(p).elementdef).ordtype in [u16bit,s16bit])
  1258. )
  1259. or
  1260. (
  1261. (tarraydef(p).lowrange=0) and
  1262. (tarraydef(p).highrange=7) and
  1263. (torddef(tarraydef(p).elementdef).ordtype in [u8bit,s8bit])
  1264. )
  1265. )
  1266. )
  1267. or
  1268. (
  1269. (tarraydef(p).elementdef.typ=floatdef) and
  1270. (
  1271. (tarraydef(p).lowrange=0) and
  1272. (tarraydef(p).highrange=1) and
  1273. (tfloatdef(tarraydef(p).elementdef).floattype=s32real)
  1274. )
  1275. )
  1276. );
  1277. end;
  1278. {$else SUPPORT_MMX}
  1279. is_mmx_able_array:=false;
  1280. {$endif SUPPORT_MMX}
  1281. end;
  1282. function def_cgsize(def: tdef): tcgsize;
  1283. begin
  1284. case def.typ of
  1285. orddef,
  1286. enumdef,
  1287. setdef:
  1288. begin
  1289. result:=int_cgsize(def.size);
  1290. if is_signed(def) then
  1291. result:=tcgsize(ord(result)+(ord(OS_S8)-ord(OS_8)));
  1292. end;
  1293. classrefdef,
  1294. pointerdef:
  1295. begin
  1296. result:=int_cgsize(def.size);
  1297. { can happen for far/huge pointers on non-i8086 }
  1298. if result=OS_NO then
  1299. internalerror(2013052201);
  1300. end;
  1301. formaldef:
  1302. result := int_cgsize(voidpointertype.size);
  1303. procvardef:
  1304. result:=int_cgsize(def.size);
  1305. stringdef :
  1306. result:=int_cgsize(def.size);
  1307. objectdef :
  1308. result:=int_cgsize(def.size);
  1309. floatdef:
  1310. if (cs_fp_emulation in current_settings.moduleswitches)
  1311. {$ifdef xtensa}
  1312. or not(tfloatdef(def).floattype=s32real)
  1313. or not(FPUXTENSA_SINGLE in fpu_capabilities[current_settings.fputype])
  1314. {$endif xtensa}
  1315. then
  1316. result:=int_cgsize(def.size)
  1317. else
  1318. result:=tfloat2tcgsize[tfloatdef(def).floattype];
  1319. recorddef :
  1320. result:=int_cgsize(def.size);
  1321. arraydef :
  1322. begin
  1323. if is_dynamic_array(def) or not is_special_array(def) then
  1324. begin
  1325. if is_vector(def) and ((TArrayDef(def).elementdef.typ = floatdef) and not (cs_fp_emulation in current_settings.moduleswitches)) then
  1326. begin
  1327. { Determine if, based on the floating-point type and the size
  1328. of the array, if it can be made into a vector }
  1329. case tfloatdef(tarraydef(def).elementdef).floattype of
  1330. s32real:
  1331. result := float_array_cgsize(def.size);
  1332. s64real:
  1333. result := double_array_cgsize(def.size);
  1334. else
  1335. { If not, fall back }
  1336. result := int_cgsize(def.size);
  1337. end;
  1338. end
  1339. else
  1340. result := int_cgsize(def.size);
  1341. end
  1342. else
  1343. result := OS_NO;
  1344. end;
  1345. else
  1346. begin
  1347. { undefined size }
  1348. result:=OS_NO;
  1349. end;
  1350. end;
  1351. end;
  1352. function cgsize_orddef(size: tcgsize): torddef;
  1353. begin
  1354. case size of
  1355. OS_8:
  1356. result:=torddef(u8inttype);
  1357. OS_S8:
  1358. result:=torddef(s8inttype);
  1359. OS_16:
  1360. result:=torddef(u16inttype);
  1361. OS_S16:
  1362. result:=torddef(s16inttype);
  1363. OS_32:
  1364. result:=torddef(u32inttype);
  1365. OS_S32:
  1366. result:=torddef(s32inttype);
  1367. OS_64:
  1368. result:=torddef(u64inttype);
  1369. OS_S64:
  1370. result:=torddef(s64inttype);
  1371. else
  1372. internalerror(2012050401);
  1373. end;
  1374. end;
  1375. function def_cgmmsize(def: tdef): tcgsize;
  1376. begin
  1377. case def.typ of
  1378. arraydef:
  1379. begin
  1380. case tarraydef(def).elementdef.typ of
  1381. orddef:
  1382. begin
  1383. { this is not correct, OS_MX normally mean that the vector
  1384. contains elements of size X. However, vectors themselves
  1385. can also have different sizes (e.g. a vector of 2 singles on
  1386. SSE) and the total size is currently more important }
  1387. case def.size of
  1388. 1: result:=OS_M8;
  1389. 2: result:=OS_M16;
  1390. 4: result:=OS_M32;
  1391. 8: result:=OS_M64;
  1392. 16: result:=OS_M128;
  1393. 32: result:=OS_M256;
  1394. 64: result:=OS_M512;
  1395. else
  1396. internalerror(2013060103);
  1397. end;
  1398. end;
  1399. floatdef:
  1400. begin
  1401. case TFloatDef(tarraydef(def).elementdef).floattype of
  1402. s32real:
  1403. case def.size of
  1404. 4: result:=OS_M32;
  1405. 16: result:=OS_M128;
  1406. 32: result:=OS_M256;
  1407. 64: result:=OS_M512;
  1408. else
  1409. internalerror(2017121400);
  1410. end;
  1411. s64real:
  1412. case def.size of
  1413. 8: result:=OS_M64;
  1414. 16: result:=OS_M128;
  1415. 32: result:=OS_M256;
  1416. 64: result:=OS_M512;
  1417. else
  1418. internalerror(2017121401);
  1419. end;
  1420. else
  1421. internalerror(2017121402);
  1422. end;
  1423. end;
  1424. else
  1425. result:=def_cgsize(def);
  1426. end;
  1427. end
  1428. else
  1429. result:=def_cgsize(def);
  1430. end;
  1431. end;
  1432. { In Windows 95 era, ordinals were restricted to [u8bit,s32bit,s16bit,bool16bit]
  1433. As of today, both signed and unsigned types from 8 to 64 bits are supported. }
  1434. function is_automatable(p : tdef) : boolean;
  1435. begin
  1436. case p.typ of
  1437. orddef:
  1438. result:=torddef(p).ordtype in [u8bit,s8bit,u16bit,s16bit,u32bit,s32bit,
  1439. u64bit,s64bit,bool16bit,scurrency];
  1440. floatdef:
  1441. result:=tfloatdef(p).floattype in [s64currency,s64real,s32real];
  1442. stringdef:
  1443. result:=tstringdef(p).stringtype in [st_ansistring,st_widestring,st_unicodestring];
  1444. variantdef:
  1445. result:=true;
  1446. objectdef:
  1447. result:=tobjectdef(p).objecttype in [odt_interfacecom,odt_dispinterface,odt_interfacecorba];
  1448. else
  1449. result:=false;
  1450. end;
  1451. end;
  1452. {# returns true, if the type passed is a varset }
  1453. function is_smallset(p : tdef) : boolean;
  1454. begin
  1455. {$if defined(cpu8bitalu)}
  1456. result:=(p.typ=setdef) and (p.size = 1)
  1457. {$elseif defined(cpu16bitalu)}
  1458. result:=(p.typ=setdef) and (p.size in [1,2])
  1459. {$else}
  1460. result:=(p.typ=setdef) and (p.size in [1,2,4])
  1461. {$endif}
  1462. end;
  1463. function is_bareprocdef(pd : tprocdef): boolean;
  1464. begin
  1465. result:=(pd.maxparacount=0) and
  1466. (is_void(pd.returndef) or
  1467. (pd.proctypeoption = potype_constructor));
  1468. end;
  1469. function is_c_variadic(pd: tabstractprocdef): boolean;
  1470. begin
  1471. result:=
  1472. (po_varargs in pd.procoptions) or
  1473. (po_variadic in pd.procoptions);
  1474. end;
  1475. function get_common_intdef(ld, rd: torddef; keep_sign_if_equal: boolean): torddef;
  1476. var
  1477. llow, lhigh: tconstexprint;
  1478. begin
  1479. llow:=min(ld.low,rd.low);
  1480. lhigh:=max(ld.high,rd.high);
  1481. case range_to_basetype(llow,lhigh) of
  1482. s8bit:
  1483. result:=torddef(s8inttype);
  1484. u8bit:
  1485. result:=torddef(u8inttype);
  1486. s16bit:
  1487. result:=torddef(s16inttype);
  1488. u16bit:
  1489. result:=torddef(u16inttype);
  1490. s32bit:
  1491. result:=torddef(s32inttype);
  1492. u32bit:
  1493. result:=torddef(u32inttype);
  1494. s64bit:
  1495. result:=torddef(s64inttype);
  1496. u64bit:
  1497. result:=torddef(u64inttype);
  1498. else
  1499. begin
  1500. { avoid warning }
  1501. result:=nil;
  1502. internalerror(200802291);
  1503. end;
  1504. end;
  1505. if keep_sign_if_equal and
  1506. (is_signed(ld)=is_signed(rd)) and
  1507. (is_signed(result)<>is_signed(ld)) then
  1508. case result.ordtype of
  1509. s8bit:
  1510. result:=torddef(u8inttype);
  1511. u8bit:
  1512. result:=torddef(s16inttype);
  1513. s16bit:
  1514. result:=torddef(u16inttype);
  1515. u16bit:
  1516. result:=torddef(s32inttype);
  1517. s32bit:
  1518. result:=torddef(u32inttype);
  1519. u32bit:
  1520. result:=torddef(s64inttype);
  1521. s64bit:
  1522. result:=torddef(u64inttype);
  1523. else
  1524. ;
  1525. end;
  1526. end;
  1527. function calc_not_ordvalue(var v:Tconstexprint;var def:tdef):boolean;
  1528. begin
  1529. if not assigned(def) or (def.typ<>orddef) then
  1530. exit(false);
  1531. result:=true;
  1532. case torddef(def).ordtype of
  1533. pasbool1,
  1534. pasbool8,
  1535. pasbool16,
  1536. pasbool32,
  1537. pasbool64:
  1538. v:=byte(not(boolean(int64(v))));
  1539. bool8bit,
  1540. bool16bit,
  1541. bool32bit,
  1542. bool64bit:
  1543. begin
  1544. if v=0 then
  1545. v:=-1
  1546. else
  1547. v:=0;
  1548. end;
  1549. uchar,
  1550. uwidechar,
  1551. u8bit,
  1552. s8bit,
  1553. u16bit,
  1554. s16bit,
  1555. s32bit,
  1556. u32bit,
  1557. s64bit,
  1558. u64bit:
  1559. begin
  1560. { unsigned, equal or bigger than the native int size? }
  1561. if (torddef(def).ordtype in [u64bit,u32bit,u16bit,u8bit,uchar,uwidechar]) and
  1562. (is_nativeord(def) or is_oversizedord(def)) then
  1563. begin
  1564. { Delphi-compatible: not dword = dword (not word = longint) }
  1565. { Extension: not qword = qword }
  1566. v:=qword(not qword(v));
  1567. { will be truncated by the ordconstnode for u32bit }
  1568. end
  1569. else
  1570. begin
  1571. v:=int64(not int64(v));
  1572. def:=get_common_intdef(torddef(def),torddef(sinttype),false);
  1573. end;
  1574. end;
  1575. else
  1576. result:=false;
  1577. end;
  1578. end;
  1579. function is_valid_univ_para_type(def: tdef): boolean;
  1580. begin
  1581. result:=
  1582. not is_open_array(def) and
  1583. not is_void(def) and
  1584. (def.typ<>formaldef);
  1585. end;
  1586. function is_nested_pd(def: tabstractprocdef): boolean;{$ifdef USEINLINE}inline;{$endif}
  1587. begin
  1588. result:=def.parast.symtablelevel>normal_function_level;
  1589. end;
  1590. function is_typeparam(def : tdef) : boolean;{$ifdef USEINLINE}inline;{$endif}
  1591. begin
  1592. result:=(def.typ=undefineddef) or (df_genconstraint in def.defoptions);
  1593. end;
  1594. function is_methodpointer(def: tdef): boolean;
  1595. begin
  1596. result:=(def.typ=procvardef) and (po_methodpointer in tprocvardef(def).procoptions);
  1597. end;
  1598. function is_block(def: tdef): boolean;
  1599. begin
  1600. result:=(def.typ=procvardef) and (po_is_block in tprocvardef(def).procoptions)
  1601. end;
  1602. function get_typekind(def:tdef):byte;
  1603. begin
  1604. case def.typ of
  1605. arraydef:
  1606. if ado_IsDynamicArray in tarraydef(def).arrayoptions then
  1607. result:=tkDynArray
  1608. else
  1609. result:=tkArray;
  1610. recorddef:
  1611. result:=tkRecord;
  1612. pointerdef:
  1613. result:=tkPointer;
  1614. orddef:
  1615. case torddef(def).ordtype of
  1616. u8bit,
  1617. u16bit,
  1618. u32bit,
  1619. s8bit,
  1620. s16bit,
  1621. s32bit:
  1622. result:=tkInteger;
  1623. u64bit:
  1624. result:=tkQWord;
  1625. s64bit:
  1626. result:=tkInt64;
  1627. pasbool1,
  1628. pasbool8,
  1629. pasbool16,
  1630. pasbool32,
  1631. pasbool64,
  1632. bool8bit,
  1633. bool16bit,
  1634. bool32bit,
  1635. bool64bit:
  1636. result:=tkBool;
  1637. uchar:
  1638. result:=tkChar;
  1639. uwidechar:
  1640. result:=tkWChar;
  1641. scurrency:
  1642. result:=tkFloat;
  1643. else
  1644. result:=tkUnknown;
  1645. end;
  1646. stringdef:
  1647. case tstringdef(def).stringtype of
  1648. st_shortstring:
  1649. result:=tkSString;
  1650. st_longstring:
  1651. result:=tkLString;
  1652. st_ansistring:
  1653. result:=tkAString;
  1654. st_widestring:
  1655. result:=tkWString;
  1656. st_unicodestring:
  1657. result:=tkUString;
  1658. end;
  1659. enumdef:
  1660. result:=tkEnumeration;
  1661. objectdef:
  1662. case tobjectdef(def).objecttype of
  1663. odt_class,
  1664. odt_javaclass:
  1665. result:=tkClass;
  1666. odt_object:
  1667. result:=tkObject;
  1668. odt_interfacecom,
  1669. odt_dispinterface,
  1670. odt_interfacejava:
  1671. result:=tkInterface;
  1672. odt_interfacecorba:
  1673. result:=tkInterfaceCorba;
  1674. odt_helper:
  1675. result:=tkHelper;
  1676. else
  1677. result:=tkUnknown;
  1678. end;
  1679. { currently tkFile is not used }
  1680. {filedef:
  1681. result:=tkFile;}
  1682. setdef:
  1683. result:=tkSet;
  1684. procvardef:
  1685. if tprocvardef(def).is_methodpointer then
  1686. result:=tkMethod
  1687. else
  1688. result:=tkProcVar;
  1689. floatdef:
  1690. result:=tkFloat;
  1691. classrefdef:
  1692. result:=tkClassRef;
  1693. variantdef:
  1694. result:=tkVariant;
  1695. else
  1696. result:=tkUnknown;
  1697. end;
  1698. end;
  1699. end.