defutil.pas 65 KB

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