defutil.pas 65 KB

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