defutil.pas 65 KB

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