defutil.pas 46 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437
  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,symcpu;
  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. {$ifdef x86}
  984. if (def.typ=pointerdef) and
  985. (tcpupointerdef(def).x86pointertyp in [x86pt_far,x86pt_huge]) then
  986. begin
  987. {$if defined(i8086)}
  988. result := OS_32;
  989. {$elseif defined(i386)}
  990. internalerror(2013052201); { there's no OS_48 }
  991. {$elseif defined(x86_64)}
  992. internalerror(2013052202); { there's no OS_80 }
  993. {$endif}
  994. end
  995. else
  996. {$endif x86}
  997. result := int_cgsize(def.size);
  998. end;
  999. formaldef:
  1000. result := int_cgsize(voidpointertype.size);
  1001. procvardef:
  1002. result:=int_cgsize(def.size);
  1003. stringdef :
  1004. result:=int_cgsize(def.size);
  1005. objectdef :
  1006. result:=int_cgsize(def.size);
  1007. floatdef:
  1008. if cs_fp_emulation in current_settings.moduleswitches then
  1009. result:=int_cgsize(def.size)
  1010. else
  1011. result:=tfloat2tcgsize[tfloatdef(def).floattype];
  1012. recorddef :
  1013. result:=int_cgsize(def.size);
  1014. arraydef :
  1015. begin
  1016. if is_dynamic_array(def) or not is_special_array(def) then
  1017. result := int_cgsize(def.size)
  1018. else
  1019. result := OS_NO;
  1020. end;
  1021. else
  1022. begin
  1023. { undefined size }
  1024. result:=OS_NO;
  1025. end;
  1026. end;
  1027. end;
  1028. function cgsize_orddef(size: tcgsize): torddef;
  1029. begin
  1030. case size of
  1031. OS_8:
  1032. result:=torddef(u8inttype);
  1033. OS_S8:
  1034. result:=torddef(s8inttype);
  1035. OS_16:
  1036. result:=torddef(u16inttype);
  1037. OS_S16:
  1038. result:=torddef(s16inttype);
  1039. OS_32:
  1040. result:=torddef(u32inttype);
  1041. OS_S32:
  1042. result:=torddef(s32inttype);
  1043. OS_64:
  1044. result:=torddef(u64inttype);
  1045. OS_S64:
  1046. result:=torddef(s64inttype);
  1047. else
  1048. internalerror(2012050401);
  1049. end;
  1050. end;
  1051. function def_cgmmsize(def: tdef): tcgsize;
  1052. begin
  1053. case def.typ of
  1054. arraydef:
  1055. begin
  1056. if tarraydef(def).elementdef.typ in [orddef,floatdef] then
  1057. begin
  1058. { this is not correct, OS_MX normally mean that the vector
  1059. contains elements of size X. However, vectors themselves
  1060. can also have different sizes (e.g. a vector of 2 singles on
  1061. SSE) and the total size is currently more important }
  1062. case def.size of
  1063. 1: result:=OS_M8;
  1064. 2: result:=OS_M16;
  1065. 4: result:=OS_M32;
  1066. 8: result:=OS_M64;
  1067. 16: result:=OS_M128;
  1068. 32: result:=OS_M256;
  1069. else
  1070. internalerror(2013060103);
  1071. end;
  1072. end
  1073. else
  1074. result:=def_cgsize(def);
  1075. end
  1076. else
  1077. result:=def_cgsize(def);
  1078. end;
  1079. end;
  1080. { In Windows 95 era, ordinals were restricted to [u8bit,s32bit,s16bit,bool16bit]
  1081. As of today, both signed and unsigned types from 8 to 64 bits are supported. }
  1082. function is_automatable(p : tdef) : boolean;
  1083. begin
  1084. result:=false;
  1085. case p.typ of
  1086. orddef:
  1087. result:=torddef(p).ordtype in [u8bit,s8bit,u16bit,s16bit,u32bit,s32bit,
  1088. u64bit,s64bit,bool16bit,scurrency];
  1089. floatdef:
  1090. result:=tfloatdef(p).floattype in [s64currency,s64real,s32real];
  1091. stringdef:
  1092. result:=tstringdef(p).stringtype in [st_ansistring,st_widestring,st_unicodestring];
  1093. variantdef:
  1094. result:=true;
  1095. objectdef:
  1096. result:=tobjectdef(p).objecttype in [odt_interfacecom,odt_dispinterface,odt_interfacecorba];
  1097. end;
  1098. end;
  1099. {# returns true, if the type passed is a varset }
  1100. function is_smallset(p : tdef) : boolean;
  1101. begin
  1102. {$if defined(cpu8bitalu)}
  1103. result:=(p.typ=setdef) and (p.size = 1)
  1104. {$elseif defined(cpu16bitalu)}
  1105. result:=(p.typ=setdef) and (p.size in [1,2])
  1106. {$else}
  1107. result:=(p.typ=setdef) and (p.size in [1,2,4])
  1108. {$endif}
  1109. end;
  1110. function is_bareprocdef(pd : tprocdef): boolean;
  1111. begin
  1112. result:=(pd.maxparacount=0) and
  1113. (is_void(pd.returndef) or
  1114. (pd.proctypeoption = potype_constructor));
  1115. end;
  1116. function get_common_intdef(ld, rd: torddef; keep_sign_if_equal: boolean): torddef;
  1117. var
  1118. llow, lhigh: tconstexprint;
  1119. begin
  1120. llow:=min(ld.low,rd.low);
  1121. lhigh:=max(ld.high,rd.high);
  1122. case range_to_basetype(llow,lhigh) of
  1123. s8bit:
  1124. result:=torddef(s8inttype);
  1125. u8bit:
  1126. result:=torddef(u8inttype);
  1127. s16bit:
  1128. result:=torddef(s16inttype);
  1129. u16bit:
  1130. result:=torddef(u16inttype);
  1131. s32bit:
  1132. result:=torddef(s32inttype);
  1133. u32bit:
  1134. result:=torddef(u32inttype);
  1135. s64bit:
  1136. result:=torddef(s64inttype);
  1137. u64bit:
  1138. result:=torddef(u64inttype);
  1139. else
  1140. begin
  1141. { avoid warning }
  1142. result:=nil;
  1143. internalerror(200802291);
  1144. end;
  1145. end;
  1146. if keep_sign_if_equal and
  1147. (is_signed(ld)=is_signed(rd)) and
  1148. (is_signed(result)<>is_signed(ld)) then
  1149. case result.ordtype of
  1150. s8bit:
  1151. result:=torddef(u8inttype);
  1152. u8bit:
  1153. result:=torddef(s16inttype);
  1154. s16bit:
  1155. result:=torddef(u16inttype);
  1156. u16bit:
  1157. result:=torddef(s32inttype);
  1158. s32bit:
  1159. result:=torddef(u32inttype);
  1160. u32bit:
  1161. result:=torddef(s64inttype);
  1162. s64bit:
  1163. result:=torddef(u64inttype);
  1164. end;
  1165. end;
  1166. function is_valid_univ_para_type(def: tdef): boolean;
  1167. begin
  1168. result:=
  1169. not is_open_array(def) and
  1170. not is_void(def) and
  1171. (def.typ<>formaldef);
  1172. end;
  1173. function is_nested_pd(def: tabstractprocdef): boolean;{$ifdef USEINLINE}inline;{$endif}
  1174. begin
  1175. result:=def.parast.symtablelevel>normal_function_level;
  1176. end;
  1177. function is_typeparam(def : tdef) : boolean;{$ifdef USEINLINE}inline;{$endif}
  1178. begin
  1179. result:=(def.typ=undefineddef);
  1180. end;
  1181. function is_methodpointer(def: tdef): boolean;
  1182. begin
  1183. result:=(def.typ=procvardef) and (po_methodpointer in tprocvardef(def).procoptions);
  1184. end;
  1185. function is_block(def: tdef): boolean;
  1186. begin
  1187. result:=(def.typ=procvardef) and (po_is_block in tprocvardef(def).procoptions)
  1188. end;
  1189. end.