defutil.pas 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450
  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);
  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(l,h:TConstExprInt):tordtype;
  47. procedure range_to_type(l,h:TConstExprInt;var def:tdef);
  48. procedure int_to_type(v:TConstExprInt;var def:tdef);
  49. {# Returns true, if definition defines an integer type }
  50. function is_integer(def : tdef) : boolean;
  51. {# Returns true if definition is a boolean }
  52. function is_boolean(def : tdef) : boolean;
  53. {# Returns true if definition is a Pascal-style boolean (1 = true, zero = false) }
  54. function is_pasbool(def : tdef) : boolean;
  55. {# Returns true if definition is a C-style boolean (non-zero value = true, zero = false) }
  56. function is_cbool(def : tdef) : boolean;
  57. {# Returns true if definition is a char
  58. This excludes the unicode char.
  59. }
  60. function is_char(def : tdef) : boolean;
  61. {# Returns true if definition is a widechar }
  62. function is_widechar(def : tdef) : boolean;
  63. {# Returns true if definition is either an AnsiChar or a WideChar }
  64. function is_anychar(def : tdef) : boolean;
  65. {# Returns true if definition is a void}
  66. function is_void(def : tdef) : boolean;
  67. {# Returns true if definition is a smallset}
  68. function is_smallset(p : tdef) : boolean;
  69. {# Returns true, if def defines a signed data type
  70. (only for ordinal types)
  71. }
  72. function is_signed(def : tdef) : boolean;
  73. {# Returns whether def_from's range is comprised in def_to's if both are
  74. orddefs, false otherwise }
  75. function is_in_limit(def_from,def_to : tdef) : boolean;
  76. {# Returns whether def is reference counted }
  77. function is_managed_type(def: tdef) : boolean;{$ifdef USEINLINE}inline;{$endif}
  78. { # Returns whether def is needs to load RTTI for reference counting }
  79. function is_rtti_managed_type(def: tdef) : boolean;
  80. { function is_in_limit_value(val_from:TConstExprInt;def_from,def_to : tdef) : boolean;}
  81. {*****************************************************************************
  82. Array helper functions
  83. *****************************************************************************}
  84. {# Returns true, if p points to a zero based (non special like open or
  85. dynamic array def).
  86. This is mainly used to see if the array
  87. is convertable to a pointer
  88. }
  89. function is_zero_based_array(p : tdef) : boolean;
  90. {# Returns true if p points to an open array definition }
  91. function is_open_array(p : tdef) : boolean;
  92. {# Returns true if p points to a dynamic array definition }
  93. function is_dynamic_array(p : tdef) : boolean;
  94. {# Returns true, if p points to an array of const definition }
  95. function is_array_constructor(p : tdef) : boolean;
  96. {# Returns true, if p points to a variant array }
  97. function is_variant_array(p : tdef) : boolean;
  98. {# Returns true, if p points to an array of const }
  99. function is_array_of_const(p : tdef) : boolean;
  100. {# Returns true, if p points any kind of special array
  101. That is if the array is an open array, a variant
  102. array, an array constants constructor, or an
  103. array of const.
  104. Bitpacked arrays aren't special in this regard though.
  105. }
  106. function is_special_array(p : tdef) : boolean;
  107. {# Returns true if p is a bitpacked array }
  108. function is_packed_array(p: tdef) : boolean;
  109. {# Returns true if p is a bitpacked record }
  110. function is_packed_record_or_object(p: tdef) : boolean;
  111. {# Returns true if p is a char array def }
  112. function is_chararray(p : tdef) : boolean;
  113. {# Returns true if p is a wide char array def }
  114. function is_widechararray(p : tdef) : boolean;
  115. {# Returns true if p is a open char array def }
  116. function is_open_chararray(p : tdef) : boolean;
  117. {# Returns true if p is a open wide char array def }
  118. function is_open_widechararray(p : tdef) : boolean;
  119. {*****************************************************************************
  120. String helper functions
  121. *****************************************************************************}
  122. {# Returns true if p points to an open string type }
  123. function is_open_string(p : tdef) : boolean;
  124. {# Returns true if p is an ansi string type }
  125. function is_ansistring(p : tdef) : boolean;
  126. {# Returns true if p is an ansi string type with codepage 0 }
  127. function is_rawbytestring(p : tdef) : boolean;
  128. {# Returns true if p is a long string type }
  129. function is_longstring(p : tdef) : boolean;
  130. {# returns true if p is a wide string type }
  131. function is_widestring(p : tdef) : boolean;
  132. {# true if p is an unicode string def }
  133. function is_unicodestring(p : tdef) : boolean;
  134. {# true if p is an unicode/wide/ansistring string def }
  135. function is_dynamicstring(p : tdef) : boolean;
  136. {# returns true if p is a wide or unicode string type }
  137. function is_wide_or_unicode_string(p : tdef) : boolean;
  138. {# Returns true if p is a short string type }
  139. function is_shortstring(p : tdef) : boolean;
  140. {# Returns true if p is a pchar def }
  141. function is_pchar(p : tdef) : boolean;
  142. {# Returns true if p is a pwidechar def }
  143. function is_pwidechar(p : tdef) : boolean;
  144. {# Returns true if p is a voidpointer def }
  145. function is_voidpointer(p : tdef) : boolean;
  146. {# Returns true, if definition is a float }
  147. function is_fpu(def : tdef) : boolean;
  148. {# Returns true, if def is a currency type }
  149. function is_currency(def : tdef) : boolean;
  150. {# Returns true, if def is a single type }
  151. function is_single(def : tdef) : boolean;
  152. {# Returns true, if def is a double type }
  153. function is_double(def : tdef) : boolean;
  154. {# Returns true, if def is an extended type }
  155. function is_extended(def : tdef) : boolean;
  156. {# Returns true, if definition is a "real" real (i.e. single/double/extended) }
  157. function is_real(def : tdef) : boolean;
  158. {# Returns true for single,double,extended and cextended }
  159. function is_real_or_cextended(def : tdef) : boolean;
  160. { true, if def is a 8 bit int type }
  161. function is_8bitint(def : tdef) : boolean;
  162. { true, if def is a 8 bit ordinal type }
  163. function is_8bit(def : tdef) : boolean;
  164. { true, if def is a 16 bit int type }
  165. function is_16bitint(def : tdef) : boolean;
  166. { true, if def is a 16 bit ordinal type }
  167. function is_16bit(def : tdef) : boolean;
  168. {# Returns true, if def is a 32 bit integer type }
  169. function is_32bitint(def : tdef) : boolean;
  170. {# Returns true, if def is a 32 bit ordinal type }
  171. function is_32bit(def : tdef) : boolean;
  172. {# Returns true, if def is a 64 bit integer type }
  173. function is_64bitint(def : tdef) : boolean;
  174. {# Returns true, if def is a 64 bit type }
  175. function is_64bit(def : tdef) : boolean;
  176. { true, if def is an int type, larger than the processor's native int size }
  177. function is_oversizedint(def : tdef) : boolean;
  178. { true, if def is an ordinal type, larger than the processor's native int size }
  179. function is_oversizedord(def : tdef) : boolean;
  180. { true, if def is an int type, equal in size to the processor's native int size }
  181. function is_nativeint(def : tdef) : boolean;
  182. { true, if def is an ordinal type, equal in size to the processor's native int size }
  183. function is_nativeord(def : tdef) : boolean;
  184. { true, if def is an unsigned int type, equal in size to the processor's native int size }
  185. function is_nativeuint(def : tdef) : boolean;
  186. { true, if def is a signed int type, equal in size to the processor's native int size }
  187. function is_nativesint(def : tdef) : boolean;
  188. {# If @var(l) isn't in the range of todef a range check error (if not explicit) is generated and
  189. the value is placed within the range
  190. }
  191. procedure testrange(todef : tdef;var l : tconstexprint;explicit,forcerangecheck:boolean);
  192. {# Returns the range of def, where @var(l) is the low-range and @var(h) is
  193. the high-range.
  194. }
  195. procedure getrange(def : tdef;out l, h : TConstExprInt);
  196. { type being a vector? }
  197. function is_vector(p : tdef) : boolean;
  198. { some type helper routines for MMX support }
  199. function is_mmx_able_array(p : tdef) : boolean;
  200. {# returns the mmx type }
  201. function mmx_type(p : tdef) : tmmxtype;
  202. { returns if the passed type (array) fits into an mm register }
  203. function fits_in_mm_register(p : tdef) : boolean;
  204. {# From a definition return the abstract code generator size enum. It is
  205. to note that the value returned can be @var(OS_NO) }
  206. function def_cgsize(def: tdef): tcgsize;
  207. { #Return an orddef (integer) correspondig to a tcgsize }
  208. function cgsize_orddef(size: tcgsize): torddef;
  209. {# Same as def_cgsize, except that it will interpret certain arrays as
  210. vectors and return OS_M* sizes for them }
  211. function def_cgmmsize(def: tdef): tcgsize;
  212. {# returns true, if the type passed is can be used with windows automation }
  213. function is_automatable(p : tdef) : boolean;
  214. { # returns true if the procdef has no parameters and no specified return type }
  215. function is_bareprocdef(pd : tprocdef): boolean;
  216. { # returns the smallest base integer type whose range encompasses that of
  217. both ld and rd; if keep_sign_if_equal, then if ld and rd have the same
  218. signdness, the result will also get that signdness }
  219. function get_common_intdef(ld, rd: torddef; keep_sign_if_equal: boolean): torddef;
  220. { # returns whether the type is potentially a valid type of/for an "univ" parameter
  221. (basically: it must have a compile-time size) }
  222. function is_valid_univ_para_type(def: tdef): boolean;
  223. { # returns whether the procdef/procvardef represents a nested procedure
  224. or not }
  225. function is_nested_pd(def: tabstractprocdef): boolean;{$ifdef USEINLINE}inline;{$endif}
  226. { # returns whether def is a type parameter of a generic }
  227. function is_typeparam(def : tdef) : boolean;{$ifdef USEINLINE}inline;{$endif}
  228. { returns true of def is a methodpointer }
  229. function is_methodpointer(def : tdef) : boolean;
  230. {$ifdef i8086}
  231. {# Returns true if p is a far pointer def }
  232. function is_farpointer(p : tdef) : boolean;
  233. {# Returns true if p is a huge pointer def }
  234. function is_hugepointer(p : tdef) : boolean;
  235. {$endif i8086}
  236. implementation
  237. uses
  238. verbose,cutils,symcpu;
  239. { returns true, if def uses FPU }
  240. function is_fpu(def : tdef) : boolean;
  241. begin
  242. is_fpu:=(def.typ=floatdef);
  243. end;
  244. { returns true, if def is a currency type }
  245. function is_currency(def : tdef) : boolean;
  246. begin
  247. case s64currencytype.typ of
  248. orddef :
  249. result:=(def.typ=orddef) and
  250. (torddef(s64currencytype).ordtype=torddef(def).ordtype);
  251. floatdef :
  252. result:=(def.typ=floatdef) and
  253. (tfloatdef(s64currencytype).floattype=tfloatdef(def).floattype);
  254. else
  255. internalerror(200304222);
  256. end;
  257. end;
  258. { returns true, if def is a single type }
  259. function is_single(def : tdef) : boolean;
  260. begin
  261. result:=(def.typ=floatdef) and
  262. (tfloatdef(def).floattype=s32real);
  263. end;
  264. { returns true, if def is a double type }
  265. function is_double(def : tdef) : boolean;
  266. begin
  267. result:=(def.typ=floatdef) and
  268. (tfloatdef(def).floattype=s64real);
  269. end;
  270. function is_extended(def : tdef) : boolean;
  271. begin
  272. result:=(def.typ=floatdef) and
  273. (tfloatdef(def).floattype in [s80real,sc80real]);
  274. end;
  275. { returns true, if definition is a "real" real (i.e. single/double/extended) }
  276. function is_real(def : tdef) : boolean;
  277. begin
  278. result:=(def.typ=floatdef) and
  279. (tfloatdef(def).floattype in [s32real,s64real,s80real]);
  280. end;
  281. function is_real_or_cextended(def: tdef): boolean;
  282. begin
  283. result:=(def.typ=floatdef) and
  284. (tfloatdef(def).floattype in [s32real,s64real,s80real,sc80real]);
  285. end;
  286. function range_to_basetype(l,h:TConstExprInt):tordtype;
  287. begin
  288. { prefer signed over unsigned }
  289. if (l>=int64(-128)) and (h<=127) then
  290. range_to_basetype:=s8bit
  291. else if (l>=0) and (h<=255) then
  292. range_to_basetype:=u8bit
  293. else if (l>=int64(-32768)) and (h<=32767) then
  294. range_to_basetype:=s16bit
  295. else if (l>=0) and (h<=65535) then
  296. range_to_basetype:=u16bit
  297. else if (l>=int64(low(longint))) and (h<=high(longint)) then
  298. range_to_basetype:=s32bit
  299. else if (l>=low(cardinal)) and (h<=high(cardinal)) then
  300. range_to_basetype:=u32bit
  301. else if (l>=low(int64)) and (h<=high(int64)) then
  302. range_to_basetype:=s64bit
  303. else
  304. range_to_basetype:=u64bit;
  305. end;
  306. procedure range_to_type(l,h:TConstExprInt;var def:tdef);
  307. begin
  308. { prefer signed over unsigned }
  309. if (l>=int64(-128)) and (h<=127) then
  310. def:=s8inttype
  311. else if (l>=0) and (h<=255) then
  312. def:=u8inttype
  313. else if (l>=int64(-32768)) and (h<=32767) then
  314. def:=s16inttype
  315. else if (l>=0) and (h<=65535) then
  316. def:=u16inttype
  317. else if (l>=int64(low(longint))) and (h<=high(longint)) then
  318. def:=s32inttype
  319. else if (l>=low(cardinal)) and (h<=high(cardinal)) then
  320. def:=u32inttype
  321. else if (l>=low(int64)) and (h<=high(int64)) then
  322. def:=s64inttype
  323. else
  324. def:=u64inttype;
  325. end;
  326. procedure int_to_type(v:TConstExprInt;var def:tdef);
  327. begin
  328. range_to_type(v,v,def);
  329. end;
  330. { true if p is an ordinal }
  331. function is_ordinal(def : tdef) : boolean;
  332. var
  333. dt : tordtype;
  334. begin
  335. case def.typ of
  336. orddef :
  337. begin
  338. dt:=torddef(def).ordtype;
  339. is_ordinal:=dt in [uchar,uwidechar,
  340. u8bit,u16bit,u32bit,u64bit,
  341. s8bit,s16bit,s32bit,s64bit,
  342. pasbool8,pasbool16,pasbool32,pasbool64,
  343. bool8bit,bool16bit,bool32bit,bool64bit];
  344. end;
  345. enumdef :
  346. is_ordinal:=true;
  347. else
  348. is_ordinal:=false;
  349. end;
  350. end;
  351. { true if p is a string }
  352. function is_string(def : tdef) : boolean;
  353. begin
  354. is_string := (assigned(def) and (def.typ = stringdef));
  355. end;
  356. function is_stringlike(def : tdef) : boolean;
  357. begin
  358. result := is_string(def) or
  359. is_anychar(def) or
  360. is_pchar(def) or
  361. is_pwidechar(def) or
  362. is_chararray(def) or
  363. is_widechararray(def) or
  364. is_open_chararray(def) or
  365. is_open_widechararray(def) or
  366. (def=java_jlstring);
  367. end;
  368. function is_enum(def : tdef) : boolean;
  369. begin
  370. result:=def.typ=enumdef;
  371. end;
  372. function is_set(def : tdef) : boolean;
  373. begin
  374. result:=def.typ=setdef;
  375. end;
  376. { returns the min. value of the type }
  377. function get_min_value(def : tdef) : TConstExprInt;
  378. begin
  379. case def.typ of
  380. orddef:
  381. result:=torddef(def).low;
  382. enumdef:
  383. result:=int64(tenumdef(def).min);
  384. else
  385. result:=0;
  386. end;
  387. end;
  388. { returns the max. value of the type }
  389. function get_max_value(def : tdef) : TConstExprInt;
  390. begin
  391. case def.typ of
  392. orddef:
  393. result:=torddef(def).high;
  394. enumdef:
  395. result:=tenumdef(def).max;
  396. else
  397. result:=0;
  398. end;
  399. end;
  400. { true if p is an integer }
  401. function is_integer(def : tdef) : boolean;
  402. begin
  403. result:=(def.typ=orddef) and
  404. (torddef(def).ordtype in [u8bit,u16bit,u32bit,u64bit,
  405. s8bit,s16bit,s32bit,s64bit]);
  406. end;
  407. { true if p is a boolean }
  408. function is_boolean(def : tdef) : boolean;
  409. begin
  410. result:=(def.typ=orddef) and
  411. (torddef(def).ordtype in [pasbool8,pasbool16,pasbool32,pasbool64,bool8bit,bool16bit,bool32bit,bool64bit]);
  412. end;
  413. function is_pasbool(def : tdef) : boolean;
  414. begin
  415. result:=(def.typ=orddef) and
  416. (torddef(def).ordtype in [pasbool8,pasbool16,pasbool32,pasbool64]);
  417. end;
  418. { true if def is a C-style boolean (non-zero value = true, zero = false) }
  419. function is_cbool(def : tdef) : boolean;
  420. begin
  421. result:=(def.typ=orddef) and
  422. (torddef(def).ordtype in [bool8bit,bool16bit,bool32bit,bool64bit]);
  423. end;
  424. { true if p is a void }
  425. function is_void(def : tdef) : boolean;
  426. begin
  427. result:=(def.typ=orddef) and
  428. (torddef(def).ordtype=uvoid);
  429. end;
  430. { true if p is a char }
  431. function is_char(def : tdef) : boolean;
  432. begin
  433. result:=(def.typ=orddef) and
  434. (torddef(def).ordtype=uchar);
  435. end;
  436. { true if p is a wchar }
  437. function is_widechar(def : tdef) : boolean;
  438. begin
  439. result:=(def.typ=orddef) and
  440. (torddef(def).ordtype=uwidechar);
  441. end;
  442. { true if p is a char or wchar }
  443. function is_anychar(def : tdef) : boolean;
  444. begin
  445. result:=(def.typ=orddef) and
  446. (torddef(def).ordtype in [uchar,uwidechar])
  447. end;
  448. { true if p is signed (integer) }
  449. function is_signed(def : tdef) : boolean;
  450. begin
  451. case def.typ of
  452. orddef :
  453. result:=torddef(def).low < 0;
  454. enumdef :
  455. result:=tenumdef(def).min < 0;
  456. arraydef :
  457. result:=is_signed(tarraydef(def).rangedef);
  458. else
  459. result:=false;
  460. end;
  461. end;
  462. function is_in_limit(def_from,def_to : tdef) : boolean;
  463. begin
  464. if (def_from.typ<>def_to.typ) or
  465. not(def_from.typ in [orddef,enumdef,setdef]) then
  466. begin
  467. is_in_limit := false;
  468. exit;
  469. end;
  470. case def_from.typ of
  471. orddef:
  472. is_in_limit:=(torddef(def_from).low>=torddef(def_to).low) and
  473. (torddef(def_from).high<=torddef(def_to).high);
  474. enumdef:
  475. is_in_limit:=(tenumdef(def_from).min>=tenumdef(def_to).min) and
  476. (tenumdef(def_from).max<=tenumdef(def_to).max);
  477. setdef:
  478. is_in_limit:=(tsetdef(def_from).setbase>=tsetdef(def_to).setbase) and
  479. (tsetdef(def_from).setmax<=tsetdef(def_to).setmax);
  480. else
  481. is_in_limit:=false;
  482. end;
  483. end;
  484. function is_managed_type(def: tdef): boolean;{$ifdef USEINLINE}inline;{$endif}
  485. begin
  486. result:=def.needs_inittable;
  487. end;
  488. function is_rtti_managed_type(def: tdef): boolean;
  489. begin
  490. result:=def.needs_inittable and not (
  491. is_interfacecom_or_dispinterface(def) or
  492. (def.typ=variantdef) or
  493. (
  494. (def.typ=stringdef) and
  495. (tstringdef(def).stringtype in [st_ansistring,st_widestring,st_unicodestring])
  496. )
  497. );
  498. end;
  499. { true, if p points to an open array def }
  500. function is_open_string(p : tdef) : boolean;
  501. begin
  502. is_open_string:=(p.typ=stringdef) and
  503. (tstringdef(p).stringtype=st_shortstring) and
  504. (tstringdef(p).len=0);
  505. end;
  506. { true, if p points to a zero based array def }
  507. function is_zero_based_array(p : tdef) : boolean;
  508. begin
  509. result:=(p.typ=arraydef) and
  510. (tarraydef(p).lowrange=0) and
  511. not(is_special_array(p));
  512. end;
  513. { true if p points to a dynamic array def }
  514. function is_dynamic_array(p : tdef) : boolean;
  515. begin
  516. result:=(p.typ=arraydef) and
  517. (ado_IsDynamicArray in tarraydef(p).arrayoptions);
  518. end;
  519. { true, if p points to an open array def }
  520. function is_open_array(p : tdef) : boolean;
  521. begin
  522. { check for ptrsinttype is needed, because for unsigned the high
  523. range is also -1 ! (PFV) }
  524. result:=(p.typ=arraydef) and
  525. (tarraydef(p).rangedef=ptrsinttype) and
  526. (tarraydef(p).lowrange=0) and
  527. (tarraydef(p).highrange=-1) and
  528. ((tarraydef(p).arrayoptions * [ado_IsVariant,ado_IsArrayOfConst,ado_IsConstructor,ado_IsDynamicArray])=[]);
  529. end;
  530. { true, if p points to an array of const def }
  531. function is_array_constructor(p : tdef) : boolean;
  532. begin
  533. result:=(p.typ=arraydef) and
  534. (ado_IsConstructor in tarraydef(p).arrayoptions);
  535. end;
  536. { true, if p points to a variant array }
  537. function is_variant_array(p : tdef) : boolean;
  538. begin
  539. result:=(p.typ=arraydef) and
  540. (ado_IsVariant in tarraydef(p).arrayoptions);
  541. end;
  542. { true, if p points to an array of const }
  543. function is_array_of_const(p : tdef) : boolean;
  544. begin
  545. result:=(p.typ=arraydef) and
  546. (ado_IsArrayOfConst in tarraydef(p).arrayoptions);
  547. end;
  548. { true, if p points to a special array, bitpacked arrays aren't special in this regard though }
  549. function is_special_array(p : tdef) : boolean;
  550. begin
  551. result:=(p.typ=arraydef) and
  552. (
  553. ((tarraydef(p).arrayoptions * [ado_IsVariant,ado_IsArrayOfConst,ado_IsConstructor,ado_IsDynamicArray])<>[]) or
  554. is_open_array(p)
  555. );
  556. end;
  557. { true if p is an ansi string def }
  558. function is_ansistring(p : tdef) : boolean;
  559. begin
  560. is_ansistring:=(p.typ=stringdef) and
  561. (tstringdef(p).stringtype=st_ansistring);
  562. end;
  563. { true if p is an ansi string def with codepage CP_NONE }
  564. function is_rawbytestring(p : tdef) : boolean;
  565. begin
  566. is_rawbytestring:=(p.typ=stringdef) and
  567. (tstringdef(p).stringtype=st_ansistring) and
  568. (tstringdef(p).encoding=globals.CP_NONE);
  569. end;
  570. { true if p is an long string def }
  571. function is_longstring(p : tdef) : boolean;
  572. begin
  573. is_longstring:=(p.typ=stringdef) and
  574. (tstringdef(p).stringtype=st_longstring);
  575. end;
  576. { true if p is an wide string def }
  577. function is_widestring(p : tdef) : boolean;
  578. begin
  579. is_widestring:=(p.typ=stringdef) and
  580. (tstringdef(p).stringtype=st_widestring);
  581. end;
  582. function is_dynamicstring(p: tdef): boolean;
  583. begin
  584. is_dynamicstring:=(p.typ=stringdef) and
  585. (tstringdef(p).stringtype in [st_ansistring,st_widestring,st_unicodestring]);
  586. end;
  587. { true if p is an wide string def }
  588. function is_wide_or_unicode_string(p : tdef) : boolean;
  589. begin
  590. is_wide_or_unicode_string:=(p.typ=stringdef) and
  591. (tstringdef(p).stringtype in [st_widestring,st_unicodestring]);
  592. end;
  593. { true if p is an unicode string def }
  594. function is_unicodestring(p : tdef) : boolean;
  595. begin
  596. is_unicodestring:=(p.typ=stringdef) and
  597. (tstringdef(p).stringtype=st_unicodestring);
  598. end;
  599. { true if p is an short string def }
  600. function is_shortstring(p : tdef) : boolean;
  601. begin
  602. is_shortstring:=(p.typ=stringdef) and
  603. (tstringdef(p).stringtype=st_shortstring);
  604. end;
  605. { true if p is bit packed array def }
  606. function is_packed_array(p: tdef) : boolean;
  607. begin
  608. is_packed_array :=
  609. (p.typ = arraydef) and
  610. (ado_IsBitPacked in tarraydef(p).arrayoptions);
  611. end;
  612. { true if p is bit packed record def }
  613. function is_packed_record_or_object(p: tdef) : boolean;
  614. begin
  615. is_packed_record_or_object :=
  616. (p.typ in [recorddef,objectdef]) and
  617. (tabstractrecorddef(p).is_packed);
  618. end;
  619. { true if p is a char array def }
  620. function is_chararray(p : tdef) : boolean;
  621. begin
  622. is_chararray:=(p.typ=arraydef) and
  623. is_char(tarraydef(p).elementdef) and
  624. not(is_special_array(p));
  625. end;
  626. { true if p is a widechar array def }
  627. function is_widechararray(p : tdef) : boolean;
  628. begin
  629. is_widechararray:=(p.typ=arraydef) and
  630. is_widechar(tarraydef(p).elementdef) and
  631. not(is_special_array(p));
  632. end;
  633. { true if p is a open char array def }
  634. function is_open_chararray(p : tdef) : boolean;
  635. begin
  636. is_open_chararray:= is_open_array(p) and
  637. is_char(tarraydef(p).elementdef);
  638. end;
  639. { true if p is a open wide char array def }
  640. function is_open_widechararray(p : tdef) : boolean;
  641. begin
  642. is_open_widechararray:= is_open_array(p) and
  643. is_widechar(tarraydef(p).elementdef);
  644. end;
  645. { true if p is a pchar def }
  646. function is_pchar(p : tdef) : boolean;
  647. begin
  648. is_pchar:=(p.typ=pointerdef) and
  649. (is_char(tpointerdef(p).pointeddef) or
  650. (is_zero_based_array(tpointerdef(p).pointeddef) and
  651. is_chararray(tpointerdef(p).pointeddef)));
  652. end;
  653. { true if p is a pchar def }
  654. function is_pwidechar(p : tdef) : boolean;
  655. begin
  656. is_pwidechar:=(p.typ=pointerdef) and
  657. (is_widechar(tpointerdef(p).pointeddef) or
  658. (is_zero_based_array(tpointerdef(p).pointeddef) and
  659. is_widechararray(tpointerdef(p).pointeddef)));
  660. end;
  661. { true if p is a voidpointer def }
  662. function is_voidpointer(p : tdef) : boolean;
  663. begin
  664. is_voidpointer:=(p.typ=pointerdef) and
  665. (tpointerdef(p).pointeddef.typ=orddef) and
  666. (torddef(tpointerdef(p).pointeddef).ordtype=uvoid);
  667. end;
  668. { true, if def is a 8 bit int type }
  669. function is_8bitint(def : tdef) : boolean;
  670. begin
  671. result:=(def.typ=orddef) and (torddef(def).ordtype in [u8bit,s8bit])
  672. end;
  673. { true, if def is a 8 bit ordinal type }
  674. function is_8bit(def : tdef) : boolean;
  675. begin
  676. result:=(def.typ=orddef) and (torddef(def).ordtype in [u8bit,s8bit,pasbool8,bool8bit,uchar])
  677. end;
  678. { true, if def is a 16 bit int type }
  679. function is_16bitint(def : tdef) : boolean;
  680. begin
  681. result:=(def.typ=orddef) and (torddef(def).ordtype in [u16bit,s16bit])
  682. end;
  683. { true, if def is a 16 bit ordinal type }
  684. function is_16bit(def : tdef) : boolean;
  685. begin
  686. result:=(def.typ=orddef) and (torddef(def).ordtype in [u16bit,s16bit,pasbool16,bool16bit,uwidechar])
  687. end;
  688. { true, if def is a 32 bit int type }
  689. function is_32bitint(def : tdef) : boolean;
  690. begin
  691. result:=(def.typ=orddef) and (torddef(def).ordtype in [u32bit,s32bit])
  692. end;
  693. { true, if def is a 32 bit ordinal type }
  694. function is_32bit(def: tdef): boolean;
  695. begin
  696. result:=(def.typ=orddef) and (torddef(def).ordtype in [u32bit,s32bit,pasbool32,bool32bit])
  697. end;
  698. { true, if def is a 64 bit int type }
  699. function is_64bitint(def : tdef) : boolean;
  700. begin
  701. is_64bitint:=(def.typ=orddef) and (torddef(def).ordtype in [u64bit,s64bit])
  702. end;
  703. { true, if def is a 64 bit type }
  704. function is_64bit(def : tdef) : boolean;
  705. begin
  706. is_64bit:=(def.typ=orddef) and (torddef(def).ordtype in [u64bit,s64bit,scurrency,pasbool64,bool64bit])
  707. end;
  708. { true, if def is an int type, larger than the processor's native int size }
  709. function is_oversizedint(def : tdef) : boolean;
  710. begin
  711. {$if defined(cpu8bitalu)}
  712. result:=is_64bitint(def) or is_32bitint(def) or is_16bitint(def);
  713. {$elseif defined(cpu16bitalu)}
  714. result:=is_64bitint(def) or is_32bitint(def);
  715. {$elseif defined(cpu32bitaddr)}
  716. result:=is_64bitint(def);
  717. {$elseif defined(cpu64bitaddr)}
  718. result:=false;
  719. {$endif}
  720. end;
  721. { true, if def is an ordinal type, larger than the processor's native int size }
  722. function is_oversizedord(def : tdef) : boolean;
  723. begin
  724. {$if defined(cpu8bitalu)}
  725. result:=is_64bit(def) or is_32bit(def) or is_16bit(def);
  726. {$elseif defined(cpu16bitalu)}
  727. result:=is_64bit(def) or is_32bit(def);
  728. {$elseif defined(cpu32bitaddr)}
  729. result:=is_64bit(def);
  730. {$elseif defined(cpu64bitaddr)}
  731. result:=false;
  732. {$endif}
  733. end;
  734. { true, if def is an int type, equal in size to the processor's native int size }
  735. function is_nativeint(def: tdef): boolean;
  736. begin
  737. {$if defined(cpu8bitalu)}
  738. result:=is_8bitint(def);
  739. {$elseif defined(cpu16bitalu)}
  740. result:=is_16bitint(def);
  741. {$elseif defined(cpu32bitaddr)}
  742. result:=is_32bitint(def);
  743. {$elseif defined(cpu64bitaddr)}
  744. result:=is_64bitint(def);
  745. {$endif}
  746. end;
  747. { true, if def is an ordinal type, equal in size to the processor's native int size }
  748. function is_nativeord(def: tdef): boolean;
  749. begin
  750. {$if defined(cpu8bitalu)}
  751. result:=is_8bit(def);
  752. {$elseif defined(cpu16bitalu)}
  753. result:=is_16bit(def);
  754. {$elseif defined(cpu32bitaddr)}
  755. result:=is_32bit(def);
  756. {$elseif defined(cpu64bitaddr)}
  757. result:=is_64bit(def);
  758. {$endif}
  759. end;
  760. { true, if def is an unsigned int type, equal in size to the processor's native int size }
  761. function is_nativeuint(def: tdef): boolean;
  762. begin
  763. result:=is_nativeint(def) and (def.typ=orddef) and (torddef(def).ordtype in [u64bit,u32bit,u16bit,u8bit]);
  764. end;
  765. { true, if def is a signed int type, equal in size to the processor's native int size }
  766. function is_nativesint(def: tdef): boolean;
  767. begin
  768. result:=is_nativeint(def) and (def.typ=orddef) and (torddef(def).ordtype in [s64bit,s32bit,s16bit,s8bit]);
  769. end;
  770. { if l isn't in the range of todef a range check error (if not explicit) is generated and
  771. the value is placed within the range }
  772. procedure testrange(todef : tdef;var l : tconstexprint;explicit,forcerangecheck:boolean);
  773. var
  774. lv,hv: TConstExprInt;
  775. begin
  776. { for 64 bit types we need only to check if it is less than }
  777. { zero, if def is a qword node }
  778. getrange(todef,lv,hv);
  779. if (l<lv) or (l>hv) then
  780. begin
  781. if not explicit then
  782. begin
  783. if ((todef.typ=enumdef) and
  784. { delphi allows range check errors in
  785. enumeration type casts FK }
  786. not(m_delphi in current_settings.modeswitches)) or
  787. (cs_check_range in current_settings.localswitches) or
  788. forcerangecheck then
  789. Message3(type_e_range_check_error_bounds,tostr(l),tostr(lv),tostr(hv))
  790. else
  791. Message3(type_w_range_check_error_bounds,tostr(l),tostr(lv),tostr(hv));
  792. end;
  793. { Fix the value to fit in the allocated space for this type of variable }
  794. case longint(todef.size) of
  795. 1: l := l and $ff;
  796. 2: l := l and $ffff;
  797. 4: l := l and $ffffffff;
  798. end;
  799. {reset sign, i.e. converting -1 to qword changes the value to high(qword)}
  800. l.signed:=false;
  801. { do sign extension if necessary (JM) }
  802. if is_signed(todef) then
  803. begin
  804. case longint(todef.size) of
  805. 1: l.svalue := shortint(l.svalue);
  806. 2: l.svalue := smallint(l.svalue);
  807. 4: l.svalue := longint(l.svalue);
  808. end;
  809. l.signed:=true;
  810. end;
  811. end;
  812. end;
  813. { return the range from def in l and h }
  814. procedure getrange(def : tdef;out l, h : TConstExprInt);
  815. begin
  816. case def.typ of
  817. orddef :
  818. begin
  819. l:=torddef(def).low;
  820. h:=torddef(def).high;
  821. end;
  822. enumdef :
  823. begin
  824. l:=int64(tenumdef(def).min);
  825. h:=int64(tenumdef(def).max);
  826. end;
  827. arraydef :
  828. begin
  829. l:=int64(tarraydef(def).lowrange);
  830. h:=int64(tarraydef(def).highrange);
  831. end;
  832. else
  833. internalerror(200611054);
  834. end;
  835. end;
  836. function mmx_type(p : tdef) : tmmxtype;
  837. begin
  838. mmx_type:=mmxno;
  839. if is_mmx_able_array(p) then
  840. begin
  841. if tarraydef(p).elementdef.typ=floatdef then
  842. case tfloatdef(tarraydef(p).elementdef).floattype of
  843. s32real:
  844. mmx_type:=mmxsingle;
  845. end
  846. else
  847. case torddef(tarraydef(p).elementdef).ordtype of
  848. u8bit:
  849. mmx_type:=mmxu8bit;
  850. s8bit:
  851. mmx_type:=mmxs8bit;
  852. u16bit:
  853. mmx_type:=mmxu16bit;
  854. s16bit:
  855. mmx_type:=mmxs16bit;
  856. u32bit:
  857. mmx_type:=mmxu32bit;
  858. s32bit:
  859. mmx_type:=mmxs32bit;
  860. end;
  861. end;
  862. end;
  863. function is_vector(p : tdef) : boolean;
  864. begin
  865. result:=(p.typ=arraydef) and
  866. not(is_special_array(p)) and
  867. (tarraydef(p).elementdef.typ=floatdef) and
  868. (tfloatdef(tarraydef(p).elementdef).floattype in [s32real,s64real]);
  869. end;
  870. { returns if the passed type (array) fits into an mm register }
  871. function fits_in_mm_register(p : tdef) : boolean;
  872. begin
  873. {$ifdef x86}
  874. result:= is_vector(p) and
  875. (
  876. (tarraydef(p).elementdef.typ=floatdef) and
  877. (
  878. (tarraydef(p).lowrange=0) and
  879. (tarraydef(p).highrange=3) and
  880. (tfloatdef(tarraydef(p).elementdef).floattype=s32real)
  881. )
  882. ) or
  883. (
  884. (tarraydef(p).elementdef.typ=floatdef) and
  885. (
  886. (tarraydef(p).lowrange=0) and
  887. (tarraydef(p).highrange=1) and
  888. (tfloatdef(tarraydef(p).elementdef).floattype=s64real)
  889. )
  890. );
  891. {$else x86}
  892. result:=false;
  893. {$endif x86}
  894. end;
  895. function is_mmx_able_array(p : tdef) : boolean;
  896. begin
  897. {$ifdef SUPPORT_MMX}
  898. if (cs_mmx_saturation in current_settings.localswitches) then
  899. begin
  900. is_mmx_able_array:=(p.typ=arraydef) and
  901. not(is_special_array(p)) and
  902. (
  903. (
  904. (tarraydef(p).elementdef.typ=orddef) and
  905. (
  906. (
  907. (tarraydef(p).lowrange=0) and
  908. (tarraydef(p).highrange=1) and
  909. (torddef(tarraydef(p).elementdef).ordtype in [u32bit,s32bit])
  910. )
  911. or
  912. (
  913. (tarraydef(p).lowrange=0) and
  914. (tarraydef(p).highrange=3) and
  915. (torddef(tarraydef(p).elementdef).ordtype in [u16bit,s16bit])
  916. )
  917. )
  918. )
  919. or
  920. (
  921. (
  922. (tarraydef(p).elementdef.typ=floatdef) and
  923. (
  924. (tarraydef(p).lowrange=0) and
  925. (tarraydef(p).highrange=1) and
  926. (tfloatdef(tarraydef(p).elementdef).floattype=s32real)
  927. )
  928. )
  929. )
  930. );
  931. end
  932. else
  933. begin
  934. is_mmx_able_array:=(p.typ=arraydef) and
  935. (
  936. (
  937. (tarraydef(p).elementdef.typ=orddef) and
  938. (
  939. (
  940. (tarraydef(p).lowrange=0) and
  941. (tarraydef(p).highrange=1) and
  942. (torddef(tarraydef(p).elementdef).ordtype in [u32bit,s32bit])
  943. )
  944. or
  945. (
  946. (tarraydef(p).lowrange=0) and
  947. (tarraydef(p).highrange=3) and
  948. (torddef(tarraydef(p).elementdef).ordtype in [u16bit,s16bit])
  949. )
  950. or
  951. (
  952. (tarraydef(p).lowrange=0) and
  953. (tarraydef(p).highrange=7) and
  954. (torddef(tarraydef(p).elementdef).ordtype in [u8bit,s8bit])
  955. )
  956. )
  957. )
  958. or
  959. (
  960. (tarraydef(p).elementdef.typ=floatdef) and
  961. (
  962. (tarraydef(p).lowrange=0) and
  963. (tarraydef(p).highrange=1) and
  964. (tfloatdef(tarraydef(p).elementdef).floattype=s32real)
  965. )
  966. )
  967. );
  968. end;
  969. {$else SUPPORT_MMX}
  970. is_mmx_able_array:=false;
  971. {$endif SUPPORT_MMX}
  972. end;
  973. function def_cgsize(def: tdef): tcgsize;
  974. begin
  975. case def.typ of
  976. orddef,
  977. enumdef,
  978. setdef:
  979. begin
  980. result:=int_cgsize(def.size);
  981. if is_signed(def) then
  982. result:=tcgsize(ord(result)+(ord(OS_S8)-ord(OS_8)));
  983. end;
  984. classrefdef,
  985. pointerdef:
  986. begin
  987. {$ifdef x86}
  988. if (def.typ=pointerdef) and
  989. (tcpupointerdef(def).x86pointertyp in [x86pt_far,x86pt_huge]) then
  990. begin
  991. {$if defined(i8086)}
  992. result := OS_32;
  993. {$elseif defined(i386)}
  994. internalerror(2013052201); { there's no OS_48 }
  995. {$elseif defined(x86_64)}
  996. internalerror(2013052202); { there's no OS_80 }
  997. {$endif}
  998. end
  999. else
  1000. {$endif x86}
  1001. result := int_cgsize(def.size);
  1002. end;
  1003. formaldef:
  1004. result := int_cgsize(voidpointertype.size);
  1005. procvardef:
  1006. result:=int_cgsize(def.size);
  1007. stringdef :
  1008. result:=int_cgsize(def.size);
  1009. objectdef :
  1010. result:=int_cgsize(def.size);
  1011. floatdef:
  1012. if cs_fp_emulation in current_settings.moduleswitches then
  1013. result:=int_cgsize(def.size)
  1014. else
  1015. result:=tfloat2tcgsize[tfloatdef(def).floattype];
  1016. recorddef :
  1017. result:=int_cgsize(def.size);
  1018. arraydef :
  1019. begin
  1020. if is_dynamic_array(def) or not is_special_array(def) then
  1021. result := int_cgsize(def.size)
  1022. else
  1023. result := OS_NO;
  1024. end;
  1025. else
  1026. begin
  1027. { undefined size }
  1028. result:=OS_NO;
  1029. end;
  1030. end;
  1031. end;
  1032. function cgsize_orddef(size: tcgsize): torddef;
  1033. begin
  1034. case size of
  1035. OS_8:
  1036. result:=torddef(u8inttype);
  1037. OS_S8:
  1038. result:=torddef(s8inttype);
  1039. OS_16:
  1040. result:=torddef(u16inttype);
  1041. OS_S16:
  1042. result:=torddef(s16inttype);
  1043. OS_32:
  1044. result:=torddef(u32inttype);
  1045. OS_S32:
  1046. result:=torddef(s32inttype);
  1047. OS_64:
  1048. result:=torddef(u64inttype);
  1049. OS_S64:
  1050. result:=torddef(s64inttype);
  1051. else
  1052. internalerror(2012050401);
  1053. end;
  1054. end;
  1055. function def_cgmmsize(def: tdef): tcgsize;
  1056. begin
  1057. case def.typ of
  1058. arraydef:
  1059. begin
  1060. if tarraydef(def).elementdef.typ in [orddef,floatdef] then
  1061. begin
  1062. { this is not correct, OS_MX normally mean that the vector
  1063. contains elements of size X. However, vectors themselves
  1064. can also have different sizes (e.g. a vector of 2 singles on
  1065. SSE) and the total size is currently more important }
  1066. case def.size of
  1067. 1: result:=OS_M8;
  1068. 2: result:=OS_M16;
  1069. 4: result:=OS_M32;
  1070. 8: result:=OS_M64;
  1071. 16: result:=OS_M128;
  1072. 32: result:=OS_M256;
  1073. else
  1074. internalerror(2013060103);
  1075. end;
  1076. end
  1077. else
  1078. result:=def_cgsize(def);
  1079. end
  1080. else
  1081. result:=def_cgsize(def);
  1082. end;
  1083. end;
  1084. { In Windows 95 era, ordinals were restricted to [u8bit,s32bit,s16bit,bool16bit]
  1085. As of today, both signed and unsigned types from 8 to 64 bits are supported. }
  1086. function is_automatable(p : tdef) : boolean;
  1087. begin
  1088. result:=false;
  1089. case p.typ of
  1090. orddef:
  1091. result:=torddef(p).ordtype in [u8bit,s8bit,u16bit,s16bit,u32bit,s32bit,
  1092. u64bit,s64bit,bool16bit,scurrency];
  1093. floatdef:
  1094. result:=tfloatdef(p).floattype in [s64currency,s64real,s32real];
  1095. stringdef:
  1096. result:=tstringdef(p).stringtype in [st_ansistring,st_widestring,st_unicodestring];
  1097. variantdef:
  1098. result:=true;
  1099. objectdef:
  1100. result:=tobjectdef(p).objecttype in [odt_interfacecom,odt_dispinterface,odt_interfacecorba];
  1101. end;
  1102. end;
  1103. {# returns true, if the type passed is a varset }
  1104. function is_smallset(p : tdef) : boolean;
  1105. begin
  1106. {$if defined(cpu8bitalu)}
  1107. result:=(p.typ=setdef) and (p.size = 1)
  1108. {$elseif defined(cpu16bitalu)}
  1109. result:=(p.typ=setdef) and (p.size in [1,2])
  1110. {$else}
  1111. result:=(p.typ=setdef) and (p.size in [1,2,4])
  1112. {$endif}
  1113. end;
  1114. function is_bareprocdef(pd : tprocdef): boolean;
  1115. begin
  1116. result:=(pd.maxparacount=0) and
  1117. (is_void(pd.returndef) or
  1118. (pd.proctypeoption = potype_constructor));
  1119. end;
  1120. function get_common_intdef(ld, rd: torddef; keep_sign_if_equal: boolean): torddef;
  1121. var
  1122. llow, lhigh: tconstexprint;
  1123. begin
  1124. llow:=min(ld.low,rd.low);
  1125. lhigh:=max(ld.high,rd.high);
  1126. case range_to_basetype(llow,lhigh) of
  1127. s8bit:
  1128. result:=torddef(s8inttype);
  1129. u8bit:
  1130. result:=torddef(u8inttype);
  1131. s16bit:
  1132. result:=torddef(s16inttype);
  1133. u16bit:
  1134. result:=torddef(u16inttype);
  1135. s32bit:
  1136. result:=torddef(s32inttype);
  1137. u32bit:
  1138. result:=torddef(u32inttype);
  1139. s64bit:
  1140. result:=torddef(s64inttype);
  1141. u64bit:
  1142. result:=torddef(u64inttype);
  1143. else
  1144. begin
  1145. { avoid warning }
  1146. result:=nil;
  1147. internalerror(200802291);
  1148. end;
  1149. end;
  1150. if keep_sign_if_equal and
  1151. (is_signed(ld)=is_signed(rd)) and
  1152. (is_signed(result)<>is_signed(ld)) then
  1153. case result.ordtype of
  1154. s8bit:
  1155. result:=torddef(u8inttype);
  1156. u8bit:
  1157. result:=torddef(s16inttype);
  1158. s16bit:
  1159. result:=torddef(u16inttype);
  1160. u16bit:
  1161. result:=torddef(s32inttype);
  1162. s32bit:
  1163. result:=torddef(u32inttype);
  1164. u32bit:
  1165. result:=torddef(s64inttype);
  1166. s64bit:
  1167. result:=torddef(u64inttype);
  1168. end;
  1169. end;
  1170. function is_valid_univ_para_type(def: tdef): boolean;
  1171. begin
  1172. result:=
  1173. not is_open_array(def) and
  1174. not is_void(def) and
  1175. (def.typ<>formaldef);
  1176. end;
  1177. function is_nested_pd(def: tabstractprocdef): boolean;{$ifdef USEINLINE}inline;{$endif}
  1178. begin
  1179. result:=def.parast.symtablelevel>normal_function_level;
  1180. end;
  1181. function is_typeparam(def : tdef) : boolean;{$ifdef USEINLINE}inline;{$endif}
  1182. begin
  1183. result:=(def.typ=undefineddef);
  1184. end;
  1185. function is_methodpointer(def: tdef): boolean;
  1186. begin
  1187. result:=(def.typ=procvardef) and (po_methodpointer in tprocvardef(def).procoptions);
  1188. end;
  1189. {$ifdef i8086}
  1190. { true if p is a far pointer def }
  1191. function is_farpointer(p : tdef) : boolean;
  1192. begin
  1193. result:=(p.typ=pointerdef) and (tcpupointerdef(p).x86pointertyp=x86pt_far);
  1194. end;
  1195. { true if p is a huge pointer def }
  1196. function is_hugepointer(p : tdef) : boolean;
  1197. begin
  1198. result:=(p.typ=pointerdef) and (tcpupointerdef(p).x86pointertyp=x86pt_huge);
  1199. end;
  1200. {$endif i8086}
  1201. end.