defutil.pas 46 KB

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