defutil.pas 46 KB

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