defutil.pas 45 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394
  1. {
  2. Copyright (c) 1998-2006 by Florian Klaempfl
  3. This unit provides some help routines for type handling
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit defutil;
  18. {$i fpcdefs.inc}
  19. interface
  20. uses
  21. globtype,globals,constexp,
  22. symconst,symtype,symdef,
  23. cgbase,cpubase;
  24. type
  25. tmmxtype = (mmxno,mmxu8bit,mmxs8bit,mmxu16bit,mmxs16bit,
  26. mmxu32bit,mmxs32bit,mmxfixed16,mmxsingle);
  27. {*****************************************************************************
  28. Basic type functions
  29. *****************************************************************************}
  30. {# Returns true, if definition defines an ordinal type }
  31. function is_ordinal(def : tdef) : boolean;
  32. {# Returns true, if definition defines a string type }
  33. function is_string(def : tdef): boolean;
  34. {# Returns True, if definition defines a type that behaves like a string,
  35. namely that can be joined and compared with another string-like type }
  36. function is_stringlike(def : tdef) : boolean;
  37. {# Returns True, if definition defines an enumeration type }
  38. function is_enum(def : tdef) : boolean;
  39. {# Returns True, if definition defines a set type }
  40. function is_set(def : tdef) : boolean;
  41. {# Returns the minimal integer value of the type }
  42. function get_min_value(def : tdef) : TConstExprInt;
  43. {# Returns the maximal integer value of the type }
  44. function get_max_value(def : tdef) : TConstExprInt;
  45. {# Returns basetype of the specified integer range }
  46. function range_to_basetype(l,h:TConstExprInt):tordtype;
  47. procedure range_to_type(l,h:TConstExprInt;var def:tdef);
  48. procedure int_to_type(v:TConstExprInt;var def:tdef);
  49. {# Returns true, if definition defines an integer type }
  50. function is_integer(def : tdef) : boolean;
  51. {# Returns true if definition is a boolean }
  52. function is_boolean(def : tdef) : boolean;
  53. {# Returns true if definition is a Pascal-style boolean (1 = true, zero = false) }
  54. function is_pasbool(def : tdef) : boolean;
  55. {# Returns true if definition is a C-style boolean (non-zero value = true, zero = false) }
  56. function is_cbool(def : tdef) : boolean;
  57. {# Returns true if definition is a char
  58. This excludes the unicode char.
  59. }
  60. function is_char(def : tdef) : boolean;
  61. {# Returns true if definition is a widechar }
  62. function is_widechar(def : tdef) : boolean;
  63. {# Returns true if definition is either an AnsiChar or a WideChar }
  64. function is_anychar(def : tdef) : boolean;
  65. {# Returns true if definition is a void}
  66. function is_void(def : tdef) : boolean;
  67. {# Returns true if definition is a smallset}
  68. function is_smallset(p : tdef) : boolean;
  69. {# Returns true, if def defines a signed data type
  70. (only for ordinal types)
  71. }
  72. function is_signed(def : tdef) : boolean;
  73. {# Returns whether def_from's range is comprised in def_to's if both are
  74. orddefs, false otherwise }
  75. function is_in_limit(def_from,def_to : tdef) : boolean;
  76. {# Returns whether def is reference counted }
  77. function is_managed_type(def: tdef) : boolean;{$ifdef USEINLINE}inline;{$endif}
  78. { function is_in_limit_value(val_from:TConstExprInt;def_from,def_to : tdef) : boolean;}
  79. {*****************************************************************************
  80. Array helper functions
  81. *****************************************************************************}
  82. {# Returns true, if p points to a zero based (non special like open or
  83. dynamic array def).
  84. This is mainly used to see if the array
  85. is convertable to a pointer
  86. }
  87. function is_zero_based_array(p : tdef) : boolean;
  88. {# Returns true if p points to an open array definition }
  89. function is_open_array(p : tdef) : boolean;
  90. {# Returns true if p points to a dynamic array definition }
  91. function is_dynamic_array(p : tdef) : boolean;
  92. {# Returns true, if p points to an array of const definition }
  93. function is_array_constructor(p : tdef) : boolean;
  94. {# Returns true, if p points to a variant array }
  95. function is_variant_array(p : tdef) : boolean;
  96. {# Returns true, if p points to an array of const }
  97. function is_array_of_const(p : tdef) : boolean;
  98. {# Returns true, if p points any kind of special array
  99. That is if the array is an open array, a variant
  100. array, an array constants constructor, or an
  101. array of const.
  102. Bitpacked arrays aren't special in this regard though.
  103. }
  104. function is_special_array(p : tdef) : boolean;
  105. {# Returns true if p is a bitpacked array }
  106. function is_packed_array(p: tdef) : boolean;
  107. {# Returns true if p is a bitpacked record }
  108. function is_packed_record_or_object(p: tdef) : boolean;
  109. {# Returns true if p is a char array def }
  110. function is_chararray(p : tdef) : boolean;
  111. {# Returns true if p is a wide char array def }
  112. function is_widechararray(p : tdef) : boolean;
  113. {# Returns true if p is a open char array def }
  114. function is_open_chararray(p : tdef) : boolean;
  115. {# Returns true if p is a open wide char array def }
  116. function is_open_widechararray(p : tdef) : boolean;
  117. {*****************************************************************************
  118. String helper functions
  119. *****************************************************************************}
  120. {# Returns true if p points to an open string type }
  121. function is_open_string(p : tdef) : boolean;
  122. {# Returns true if p is an ansi string type }
  123. function is_ansistring(p : tdef) : boolean;
  124. {# Returns true if p is an ansi string type with codepage 0 }
  125. function is_rawbytestring(p : tdef) : boolean;
  126. {# Returns true if p is a long string type }
  127. function is_longstring(p : tdef) : boolean;
  128. {# returns true if p is a wide string type }
  129. function is_widestring(p : tdef) : boolean;
  130. {# true if p is an unicode string def }
  131. function is_unicodestring(p : tdef) : boolean;
  132. {# true if p is an unicode/wide/ansistring string def }
  133. function is_dynamicstring(p : tdef) : boolean;
  134. {# returns true if p is a wide or unicode string type }
  135. function is_wide_or_unicode_string(p : tdef) : boolean;
  136. {# Returns true if p is a short string type }
  137. function is_shortstring(p : tdef) : boolean;
  138. {# Returns true if p is a pchar def }
  139. function is_pchar(p : tdef) : boolean;
  140. {# Returns true if p is a pwidechar def }
  141. function is_pwidechar(p : tdef) : boolean;
  142. {# Returns true if p is a voidpointer def }
  143. function is_voidpointer(p : tdef) : boolean;
  144. {# Returns true, if definition is a float }
  145. function is_fpu(def : tdef) : boolean;
  146. {# Returns true, if def is a currency type }
  147. function is_currency(def : tdef) : boolean;
  148. {# Returns true, if def is a single type }
  149. function is_single(def : tdef) : boolean;
  150. {# Returns true, if def is a double type }
  151. function is_double(def : tdef) : boolean;
  152. {# Returns true, if def is an extended type }
  153. function is_extended(def : tdef) : boolean;
  154. {# Returns true, if definition is a "real" real (i.e. single/double/extended) }
  155. function is_real(def : tdef) : boolean;
  156. { true, if def is a 8 bit int type }
  157. function is_8bitint(def : tdef) : boolean;
  158. { true, if def is a 8 bit ordinal type }
  159. function is_8bit(def : tdef) : boolean;
  160. { true, if def is a 16 bit int type }
  161. function is_16bitint(def : tdef) : boolean;
  162. { true, if def is a 16 bit ordinal type }
  163. function is_16bit(def : tdef) : boolean;
  164. {# Returns true, if def is a 32 bit integer type }
  165. function is_32bitint(def : tdef) : boolean;
  166. {# Returns true, if def is a 32 bit ordinal type }
  167. function is_32bit(def : tdef) : boolean;
  168. {# Returns true, if def is a 64 bit integer type }
  169. function is_64bitint(def : tdef) : boolean;
  170. {# Returns true, if def is a 64 bit type }
  171. function is_64bit(def : tdef) : boolean;
  172. { true, if def is an int type, larger than the processor's native int size }
  173. function is_oversizedint(def : tdef) : boolean;
  174. { true, if def is an ordinal type, larger than the processor's native int size }
  175. function is_oversizedord(def : tdef) : boolean;
  176. { true, if def is an int type, equal in size to the processor's native int size }
  177. function is_nativeint(def : tdef) : boolean;
  178. { true, if def is an ordinal type, equal in size to the processor's native int size }
  179. function is_nativeord(def : tdef) : boolean;
  180. { true, if def is an unsigned int type, equal in size to the processor's native int size }
  181. function is_nativeuint(def : tdef) : boolean;
  182. { true, if def is a signed int type, equal in size to the processor's native int size }
  183. function is_nativesint(def : tdef) : boolean;
  184. {# If @var(l) isn't in the range of todef a range check error (if not explicit) is generated and
  185. the value is placed within the range
  186. }
  187. procedure testrange(todef : tdef;var l : tconstexprint;explicit,forcerangecheck:boolean);
  188. {# Returns the range of def, where @var(l) is the low-range and @var(h) is
  189. the high-range.
  190. }
  191. procedure getrange(def : tdef;out l, h : TConstExprInt);
  192. { type being a vector? }
  193. function is_vector(p : tdef) : boolean;
  194. { some type helper routines for MMX support }
  195. function is_mmx_able_array(p : tdef) : boolean;
  196. {# returns the mmx type }
  197. function mmx_type(p : tdef) : tmmxtype;
  198. { returns if the passed type (array) fits into an mm register }
  199. function fits_in_mm_register(p : tdef) : boolean;
  200. {# From a definition return the abstract code generator size enum. It is
  201. to note that the value returned can be @var(OS_NO) }
  202. function def_cgsize(def: tdef): tcgsize;
  203. { #Return an orddef (integer) correspondig to a tcgsize }
  204. function cgsize_orddef(size: tcgsize): torddef;
  205. {# returns true, if the type passed is can be used with windows automation }
  206. function is_automatable(p : tdef) : boolean;
  207. { # returns true if the procdef has no parameters and no specified return type }
  208. function is_bareprocdef(pd : tprocdef): boolean;
  209. { # returns the smallest base integer type whose range encompasses that of
  210. both ld and rd; if keep_sign_if_equal, then if ld and rd have the same
  211. signdness, the result will also get that signdness }
  212. function get_common_intdef(ld, rd: torddef; keep_sign_if_equal: boolean): torddef;
  213. { # returns whether the type is potentially a valid type of/for an "univ" parameter
  214. (basically: it must have a compile-time size) }
  215. function is_valid_univ_para_type(def: tdef): boolean;
  216. { # returns whether the procdef/procvardef represents a nested procedure
  217. or not }
  218. function is_nested_pd(def: tabstractprocdef): boolean;{$ifdef USEINLINE}inline;{$endif}
  219. { # returns whether def is a type parameter of a generic }
  220. function is_typeparam(def : tdef) : boolean;{$ifdef USEINLINE}inline;{$endif}
  221. { returns true of def is a methodpointer }
  222. function is_methodpointer(def : tdef) : boolean;
  223. implementation
  224. uses
  225. verbose,cutils;
  226. { returns true, if def uses FPU }
  227. function is_fpu(def : tdef) : boolean;
  228. begin
  229. is_fpu:=(def.typ=floatdef);
  230. end;
  231. { returns true, if def is a currency type }
  232. function is_currency(def : tdef) : boolean;
  233. begin
  234. case s64currencytype.typ of
  235. orddef :
  236. result:=(def.typ=orddef) and
  237. (torddef(s64currencytype).ordtype=torddef(def).ordtype);
  238. floatdef :
  239. result:=(def.typ=floatdef) and
  240. (tfloatdef(s64currencytype).floattype=tfloatdef(def).floattype);
  241. else
  242. internalerror(200304222);
  243. end;
  244. end;
  245. { returns true, if def is a single type }
  246. function is_single(def : tdef) : boolean;
  247. begin
  248. result:=(def.typ=floatdef) and
  249. (tfloatdef(def).floattype=s32real);
  250. end;
  251. { returns true, if def is a double type }
  252. function is_double(def : tdef) : boolean;
  253. begin
  254. result:=(def.typ=floatdef) and
  255. (tfloatdef(def).floattype=s64real);
  256. end;
  257. function is_extended(def : tdef) : boolean;
  258. begin
  259. result:=(def.typ=floatdef) and
  260. (tfloatdef(def).floattype in [s80real,sc80real]);
  261. end;
  262. { returns true, if definition is a "real" real (i.e. single/double/extended) }
  263. function is_real(def : tdef) : boolean;
  264. begin
  265. result:=(def.typ=floatdef) and
  266. (tfloatdef(def).floattype in [s32real,s64real,s80real]);
  267. end;
  268. function range_to_basetype(l,h:TConstExprInt):tordtype;
  269. begin
  270. { prefer signed over unsigned }
  271. if (l>=int64(-128)) and (h<=127) then
  272. range_to_basetype:=s8bit
  273. else if (l>=0) and (h<=255) then
  274. range_to_basetype:=u8bit
  275. else if (l>=int64(-32768)) and (h<=32767) then
  276. range_to_basetype:=s16bit
  277. else if (l>=0) and (h<=65535) then
  278. range_to_basetype:=u16bit
  279. else if (l>=int64(low(longint))) and (h<=high(longint)) then
  280. range_to_basetype:=s32bit
  281. else if (l>=low(cardinal)) and (h<=high(cardinal)) then
  282. range_to_basetype:=u32bit
  283. else if (l>=low(int64)) and (h<=high(int64)) then
  284. range_to_basetype:=s64bit
  285. else
  286. range_to_basetype:=u64bit;
  287. end;
  288. procedure range_to_type(l,h:TConstExprInt;var def:tdef);
  289. begin
  290. { prefer signed over unsigned }
  291. if (l>=int64(-128)) and (h<=127) then
  292. def:=s8inttype
  293. else if (l>=0) and (h<=255) then
  294. def:=u8inttype
  295. else if (l>=int64(-32768)) and (h<=32767) then
  296. def:=s16inttype
  297. else if (l>=0) and (h<=65535) then
  298. def:=u16inttype
  299. else if (l>=int64(low(longint))) and (h<=high(longint)) then
  300. def:=s32inttype
  301. else if (l>=low(cardinal)) and (h<=high(cardinal)) then
  302. def:=u32inttype
  303. else if (l>=low(int64)) and (h<=high(int64)) then
  304. def:=s64inttype
  305. else
  306. def:=u64inttype;
  307. end;
  308. procedure int_to_type(v:TConstExprInt;var def:tdef);
  309. begin
  310. range_to_type(v,v,def);
  311. end;
  312. { true if p is an ordinal }
  313. function is_ordinal(def : tdef) : boolean;
  314. var
  315. dt : tordtype;
  316. begin
  317. case def.typ of
  318. orddef :
  319. begin
  320. dt:=torddef(def).ordtype;
  321. is_ordinal:=dt in [uchar,uwidechar,
  322. u8bit,u16bit,u32bit,u64bit,
  323. s8bit,s16bit,s32bit,s64bit,
  324. pasbool8,pasbool16,pasbool32,pasbool64,
  325. bool8bit,bool16bit,bool32bit,bool64bit];
  326. end;
  327. enumdef :
  328. is_ordinal:=true;
  329. else
  330. is_ordinal:=false;
  331. end;
  332. end;
  333. { true if p is a string }
  334. function is_string(def : tdef) : boolean;
  335. begin
  336. is_string := (assigned(def) and (def.typ = stringdef));
  337. end;
  338. function is_stringlike(def : tdef) : boolean;
  339. begin
  340. result := is_string(def) or
  341. is_anychar(def) or
  342. is_pchar(def) or
  343. is_pwidechar(def) or
  344. is_chararray(def) or
  345. is_widechararray(def) or
  346. is_open_chararray(def) or
  347. is_open_widechararray(def) or
  348. (def=java_jlstring);
  349. end;
  350. function is_enum(def : tdef) : boolean;
  351. begin
  352. result:=def.typ=enumdef;
  353. end;
  354. function is_set(def : tdef) : boolean;
  355. begin
  356. result:=def.typ=setdef;
  357. end;
  358. { returns the min. value of the type }
  359. function get_min_value(def : tdef) : TConstExprInt;
  360. begin
  361. case def.typ of
  362. orddef:
  363. result:=torddef(def).low;
  364. enumdef:
  365. result:=int64(tenumdef(def).min);
  366. else
  367. result:=0;
  368. end;
  369. end;
  370. { returns the max. value of the type }
  371. function get_max_value(def : tdef) : TConstExprInt;
  372. begin
  373. case def.typ of
  374. orddef:
  375. result:=torddef(def).high;
  376. enumdef:
  377. result:=tenumdef(def).max;
  378. else
  379. result:=0;
  380. end;
  381. end;
  382. { true if p is an integer }
  383. function is_integer(def : tdef) : boolean;
  384. begin
  385. result:=(def.typ=orddef) and
  386. (torddef(def).ordtype in [u8bit,u16bit,u32bit,u64bit,
  387. s8bit,s16bit,s32bit,s64bit]);
  388. end;
  389. { true if p is a boolean }
  390. function is_boolean(def : tdef) : boolean;
  391. begin
  392. result:=(def.typ=orddef) and
  393. (torddef(def).ordtype in [pasbool8,pasbool16,pasbool32,pasbool64,bool8bit,bool16bit,bool32bit,bool64bit]);
  394. end;
  395. function is_pasbool(def : tdef) : boolean;
  396. begin
  397. result:=(def.typ=orddef) and
  398. (torddef(def).ordtype in [pasbool8,pasbool16,pasbool32,pasbool64]);
  399. end;
  400. { true if def is a C-style boolean (non-zero value = true, zero = false) }
  401. function is_cbool(def : tdef) : boolean;
  402. begin
  403. result:=(def.typ=orddef) and
  404. (torddef(def).ordtype in [bool8bit,bool16bit,bool32bit,bool64bit]);
  405. end;
  406. { true if p is a void }
  407. function is_void(def : tdef) : boolean;
  408. begin
  409. result:=(def.typ=orddef) and
  410. (torddef(def).ordtype=uvoid);
  411. end;
  412. { true if p is a char }
  413. function is_char(def : tdef) : boolean;
  414. begin
  415. result:=(def.typ=orddef) and
  416. (torddef(def).ordtype=uchar);
  417. end;
  418. { true if p is a wchar }
  419. function is_widechar(def : tdef) : boolean;
  420. begin
  421. result:=(def.typ=orddef) and
  422. (torddef(def).ordtype=uwidechar);
  423. end;
  424. { true if p is a char or wchar }
  425. function is_anychar(def : tdef) : boolean;
  426. begin
  427. result:=(def.typ=orddef) and
  428. (torddef(def).ordtype in [uchar,uwidechar])
  429. end;
  430. { true if p is signed (integer) }
  431. function is_signed(def : tdef) : boolean;
  432. begin
  433. case def.typ of
  434. orddef :
  435. result:=torddef(def).low < 0;
  436. enumdef :
  437. result:=tenumdef(def).min < 0;
  438. arraydef :
  439. result:=is_signed(tarraydef(def).rangedef);
  440. else
  441. result:=false;
  442. end;
  443. end;
  444. function is_in_limit(def_from,def_to : tdef) : boolean;
  445. begin
  446. if (def_from.typ<>def_to.typ) or
  447. not(def_from.typ in [orddef,enumdef,setdef]) then
  448. begin
  449. is_in_limit := false;
  450. exit;
  451. end;
  452. case def_from.typ of
  453. orddef:
  454. is_in_limit:=(torddef(def_from).low>=torddef(def_to).low) and
  455. (torddef(def_from).high<=torddef(def_to).high);
  456. enumdef:
  457. is_in_limit:=(tenumdef(def_from).min>=tenumdef(def_to).min) and
  458. (tenumdef(def_from).max<=tenumdef(def_to).max);
  459. setdef:
  460. is_in_limit:=(tsetdef(def_from).setbase>=tsetdef(def_to).setbase) and
  461. (tsetdef(def_from).setmax<=tsetdef(def_to).setmax);
  462. else
  463. is_in_limit:=false;
  464. end;
  465. end;
  466. function is_managed_type(def: tdef): boolean;{$ifdef USEINLINE}inline;{$endif}
  467. begin
  468. result:=def.needs_inittable;
  469. end;
  470. { true, if p points to an open array def }
  471. function is_open_string(p : tdef) : boolean;
  472. begin
  473. is_open_string:=(p.typ=stringdef) and
  474. (tstringdef(p).stringtype=st_shortstring) and
  475. (tstringdef(p).len=0);
  476. end;
  477. { true, if p points to a zero based array def }
  478. function is_zero_based_array(p : tdef) : boolean;
  479. begin
  480. result:=(p.typ=arraydef) and
  481. (tarraydef(p).lowrange=0) and
  482. not(is_special_array(p));
  483. end;
  484. { true if p points to a dynamic array def }
  485. function is_dynamic_array(p : tdef) : boolean;
  486. begin
  487. result:=(p.typ=arraydef) and
  488. (ado_IsDynamicArray in tarraydef(p).arrayoptions);
  489. end;
  490. { true, if p points to an open array def }
  491. function is_open_array(p : tdef) : boolean;
  492. begin
  493. { check for s32inttype is needed, because for u32bit the high
  494. range is also -1 ! (PFV) }
  495. result:=(p.typ=arraydef) and
  496. (tarraydef(p).rangedef=s32inttype) and
  497. (tarraydef(p).lowrange=0) and
  498. (tarraydef(p).highrange=-1) and
  499. ((tarraydef(p).arrayoptions * [ado_IsVariant,ado_IsArrayOfConst,ado_IsConstructor,ado_IsDynamicArray])=[]);
  500. end;
  501. { true, if p points to an array of const def }
  502. function is_array_constructor(p : tdef) : boolean;
  503. begin
  504. result:=(p.typ=arraydef) and
  505. (ado_IsConstructor in tarraydef(p).arrayoptions);
  506. end;
  507. { true, if p points to a variant array }
  508. function is_variant_array(p : tdef) : boolean;
  509. begin
  510. result:=(p.typ=arraydef) and
  511. (ado_IsVariant in tarraydef(p).arrayoptions);
  512. end;
  513. { true, if p points to an array of const }
  514. function is_array_of_const(p : tdef) : boolean;
  515. begin
  516. result:=(p.typ=arraydef) and
  517. (ado_IsArrayOfConst in tarraydef(p).arrayoptions);
  518. end;
  519. { true, if p points to a special array, bitpacked arrays aren't special in this regard though }
  520. function is_special_array(p : tdef) : boolean;
  521. begin
  522. result:=(p.typ=arraydef) and
  523. (
  524. ((tarraydef(p).arrayoptions * [ado_IsVariant,ado_IsArrayOfConst,ado_IsConstructor,ado_IsDynamicArray])<>[]) or
  525. is_open_array(p)
  526. );
  527. end;
  528. { true if p is an ansi string def }
  529. function is_ansistring(p : tdef) : boolean;
  530. begin
  531. is_ansistring:=(p.typ=stringdef) and
  532. (tstringdef(p).stringtype=st_ansistring);
  533. end;
  534. { true if p is an ansi string def with codepage CP_NONE }
  535. function is_rawbytestring(p : tdef) : boolean;
  536. begin
  537. is_rawbytestring:=(p.typ=stringdef) and
  538. (tstringdef(p).stringtype=st_ansistring) and
  539. (tstringdef(p).encoding=globals.CP_NONE);
  540. end;
  541. { true if p is an long string def }
  542. function is_longstring(p : tdef) : boolean;
  543. begin
  544. is_longstring:=(p.typ=stringdef) and
  545. (tstringdef(p).stringtype=st_longstring);
  546. end;
  547. { true if p is an wide string def }
  548. function is_widestring(p : tdef) : boolean;
  549. begin
  550. is_widestring:=(p.typ=stringdef) and
  551. (tstringdef(p).stringtype=st_widestring);
  552. end;
  553. function is_dynamicstring(p: tdef): boolean;
  554. begin
  555. is_dynamicstring:=(p.typ=stringdef) and
  556. (tstringdef(p).stringtype in [st_ansistring,st_widestring,st_unicodestring]);
  557. end;
  558. { true if p is an wide string def }
  559. function is_wide_or_unicode_string(p : tdef) : boolean;
  560. begin
  561. is_wide_or_unicode_string:=(p.typ=stringdef) and
  562. (tstringdef(p).stringtype in [st_widestring,st_unicodestring]);
  563. end;
  564. { true if p is an unicode string def }
  565. function is_unicodestring(p : tdef) : boolean;
  566. begin
  567. is_unicodestring:=(p.typ=stringdef) and
  568. (tstringdef(p).stringtype=st_unicodestring);
  569. end;
  570. { true if p is an short string def }
  571. function is_shortstring(p : tdef) : boolean;
  572. begin
  573. is_shortstring:=(p.typ=stringdef) and
  574. (tstringdef(p).stringtype=st_shortstring);
  575. end;
  576. { true if p is bit packed array def }
  577. function is_packed_array(p: tdef) : boolean;
  578. begin
  579. is_packed_array :=
  580. (p.typ = arraydef) and
  581. (ado_IsBitPacked in tarraydef(p).arrayoptions);
  582. end;
  583. { true if p is bit packed record def }
  584. function is_packed_record_or_object(p: tdef) : boolean;
  585. begin
  586. is_packed_record_or_object :=
  587. (p.typ in [recorddef,objectdef]) and
  588. (tabstractrecorddef(p).is_packed);
  589. end;
  590. { true if p is a char array def }
  591. function is_chararray(p : tdef) : boolean;
  592. begin
  593. is_chararray:=(p.typ=arraydef) and
  594. is_char(tarraydef(p).elementdef) and
  595. not(is_special_array(p));
  596. end;
  597. { true if p is a widechar array def }
  598. function is_widechararray(p : tdef) : boolean;
  599. begin
  600. is_widechararray:=(p.typ=arraydef) and
  601. is_widechar(tarraydef(p).elementdef) and
  602. not(is_special_array(p));
  603. end;
  604. { true if p is a open char array def }
  605. function is_open_chararray(p : tdef) : boolean;
  606. begin
  607. is_open_chararray:= is_open_array(p) and
  608. is_char(tarraydef(p).elementdef);
  609. end;
  610. { true if p is a open wide char array def }
  611. function is_open_widechararray(p : tdef) : boolean;
  612. begin
  613. is_open_widechararray:= is_open_array(p) and
  614. is_widechar(tarraydef(p).elementdef);
  615. end;
  616. { true if p is a pchar def }
  617. function is_pchar(p : tdef) : boolean;
  618. begin
  619. is_pchar:=(p.typ=pointerdef) and
  620. (is_char(tpointerdef(p).pointeddef) or
  621. (is_zero_based_array(tpointerdef(p).pointeddef) and
  622. is_chararray(tpointerdef(p).pointeddef)));
  623. end;
  624. { true if p is a pchar def }
  625. function is_pwidechar(p : tdef) : boolean;
  626. begin
  627. is_pwidechar:=(p.typ=pointerdef) and
  628. (is_widechar(tpointerdef(p).pointeddef) or
  629. (is_zero_based_array(tpointerdef(p).pointeddef) and
  630. is_widechararray(tpointerdef(p).pointeddef)));
  631. end;
  632. { true if p is a voidpointer def }
  633. function is_voidpointer(p : tdef) : boolean;
  634. begin
  635. is_voidpointer:=(p.typ=pointerdef) and
  636. (tpointerdef(p).pointeddef.typ=orddef) and
  637. (torddef(tpointerdef(p).pointeddef).ordtype=uvoid);
  638. end;
  639. { true, if def is a 8 bit int type }
  640. function is_8bitint(def : tdef) : boolean;
  641. begin
  642. result:=(def.typ=orddef) and (torddef(def).ordtype in [u8bit,s8bit])
  643. end;
  644. { true, if def is a 8 bit ordinal type }
  645. function is_8bit(def : tdef) : boolean;
  646. begin
  647. result:=(def.typ=orddef) and (torddef(def).ordtype in [u8bit,s8bit,pasbool8,bool8bit,uchar])
  648. end;
  649. { true, if def is a 16 bit int type }
  650. function is_16bitint(def : tdef) : boolean;
  651. begin
  652. result:=(def.typ=orddef) and (torddef(def).ordtype in [u16bit,s16bit])
  653. end;
  654. { true, if def is a 16 bit ordinal type }
  655. function is_16bit(def : tdef) : boolean;
  656. begin
  657. result:=(def.typ=orddef) and (torddef(def).ordtype in [u16bit,s16bit,pasbool16,bool16bit,uwidechar])
  658. end;
  659. { true, if def is a 32 bit int type }
  660. function is_32bitint(def : tdef) : boolean;
  661. begin
  662. result:=(def.typ=orddef) and (torddef(def).ordtype in [u32bit,s32bit])
  663. end;
  664. { true, if def is a 32 bit ordinal type }
  665. function is_32bit(def: tdef): boolean;
  666. begin
  667. result:=(def.typ=orddef) and (torddef(def).ordtype in [u32bit,s32bit,pasbool32,bool32bit])
  668. end;
  669. { true, if def is a 64 bit int type }
  670. function is_64bitint(def : tdef) : boolean;
  671. begin
  672. is_64bitint:=(def.typ=orddef) and (torddef(def).ordtype in [u64bit,s64bit])
  673. end;
  674. { true, if def is a 64 bit type }
  675. function is_64bit(def : tdef) : boolean;
  676. begin
  677. is_64bit:=(def.typ=orddef) and (torddef(def).ordtype in [u64bit,s64bit,scurrency,pasbool64,bool64bit])
  678. end;
  679. { true, if def is an int type, larger than the processor's native int size }
  680. function is_oversizedint(def : tdef) : boolean;
  681. begin
  682. {$if defined(cpu8bitalu)}
  683. result:=is_64bitint(def) or is_32bitint(def) or is_16bitint(def);
  684. {$elseif defined(cpu16bitalu)}
  685. result:=is_64bitint(def) or is_32bitint(def);
  686. {$elseif defined(cpu32bitaddr)}
  687. result:=is_64bitint(def);
  688. {$elseif defined(cpu64bitaddr)}
  689. result:=false;
  690. {$endif}
  691. end;
  692. { true, if def is an ordinal type, larger than the processor's native int size }
  693. function is_oversizedord(def : tdef) : boolean;
  694. begin
  695. {$if defined(cpu8bitalu)}
  696. result:=is_64bit(def) or is_32bit(def) or is_16bit(def);
  697. {$elseif defined(cpu16bitalu)}
  698. result:=is_64bit(def) or is_32bit(def);
  699. {$elseif defined(cpu32bitaddr)}
  700. result:=is_64bit(def);
  701. {$elseif defined(cpu64bitaddr)}
  702. result:=false;
  703. {$endif}
  704. end;
  705. { true, if def is an int type, equal in size to the processor's native int size }
  706. function is_nativeint(def: tdef): boolean;
  707. begin
  708. {$if defined(cpu8bitalu)}
  709. result:=is_8bitint(def);
  710. {$elseif defined(cpu16bitalu)}
  711. result:=is_16bitint(def);
  712. {$elseif defined(cpu32bitaddr)}
  713. result:=is_32bitint(def);
  714. {$elseif defined(cpu64bitaddr)}
  715. result:=is_64bitint(def);
  716. {$endif}
  717. end;
  718. { true, if def is an ordinal type, equal in size to the processor's native int size }
  719. function is_nativeord(def: tdef): boolean;
  720. begin
  721. {$if defined(cpu8bitalu)}
  722. result:=is_8bit(def);
  723. {$elseif defined(cpu16bitalu)}
  724. result:=is_16bit(def);
  725. {$elseif defined(cpu32bitaddr)}
  726. result:=is_32bit(def);
  727. {$elseif defined(cpu64bitaddr)}
  728. result:=is_64bit(def);
  729. {$endif}
  730. end;
  731. { true, if def is an unsigned int type, equal in size to the processor's native int size }
  732. function is_nativeuint(def: tdef): boolean;
  733. begin
  734. result:=is_nativeint(def) and (def.typ=orddef) and (torddef(def).ordtype in [u64bit,u32bit,u16bit,u8bit]);
  735. end;
  736. { true, if def is a signed int type, equal in size to the processor's native int size }
  737. function is_nativesint(def: tdef): boolean;
  738. begin
  739. result:=is_nativeint(def) and (def.typ=orddef) and (torddef(def).ordtype in [s64bit,s32bit,s16bit,s8bit]);
  740. end;
  741. { if l isn't in the range of todef a range check error (if not explicit) is generated and
  742. the value is placed within the range }
  743. procedure testrange(todef : tdef;var l : tconstexprint;explicit,forcerangecheck:boolean);
  744. var
  745. lv,hv: TConstExprInt;
  746. begin
  747. { for 64 bit types we need only to check if it is less than }
  748. { zero, if def is a qword node }
  749. getrange(todef,lv,hv);
  750. if (l<lv) or (l>hv) then
  751. begin
  752. if not explicit then
  753. begin
  754. if ((todef.typ=enumdef) and
  755. { delphi allows range check errors in
  756. enumeration type casts FK }
  757. not(m_delphi in current_settings.modeswitches)) or
  758. (cs_check_range in current_settings.localswitches) or
  759. forcerangecheck then
  760. Message3(type_e_range_check_error_bounds,tostr(l),tostr(lv),tostr(hv))
  761. else
  762. Message3(type_w_range_check_error_bounds,tostr(l),tostr(lv),tostr(hv));
  763. end;
  764. { Fix the value to fit in the allocated space for this type of variable }
  765. case longint(todef.size) of
  766. 1: l := l and $ff;
  767. 2: l := l and $ffff;
  768. 4: l := l and $ffffffff;
  769. end;
  770. {reset sign, i.e. converting -1 to qword changes the value to high(qword)}
  771. l.signed:=false;
  772. { do sign extension if necessary (JM) }
  773. if is_signed(todef) then
  774. begin
  775. case longint(todef.size) of
  776. 1: l.svalue := shortint(l.svalue);
  777. 2: l.svalue := smallint(l.svalue);
  778. 4: l.svalue := longint(l.svalue);
  779. end;
  780. l.signed:=true;
  781. end;
  782. end;
  783. end;
  784. { return the range from def in l and h }
  785. procedure getrange(def : tdef;out l, h : TConstExprInt);
  786. begin
  787. case def.typ of
  788. orddef :
  789. begin
  790. l:=torddef(def).low;
  791. h:=torddef(def).high;
  792. end;
  793. enumdef :
  794. begin
  795. l:=int64(tenumdef(def).min);
  796. h:=int64(tenumdef(def).max);
  797. end;
  798. arraydef :
  799. begin
  800. l:=int64(tarraydef(def).lowrange);
  801. h:=int64(tarraydef(def).highrange);
  802. end;
  803. else
  804. internalerror(200611054);
  805. end;
  806. end;
  807. function mmx_type(p : tdef) : tmmxtype;
  808. begin
  809. mmx_type:=mmxno;
  810. if is_mmx_able_array(p) then
  811. begin
  812. if tarraydef(p).elementdef.typ=floatdef then
  813. case tfloatdef(tarraydef(p).elementdef).floattype of
  814. s32real:
  815. mmx_type:=mmxsingle;
  816. end
  817. else
  818. case torddef(tarraydef(p).elementdef).ordtype of
  819. u8bit:
  820. mmx_type:=mmxu8bit;
  821. s8bit:
  822. mmx_type:=mmxs8bit;
  823. u16bit:
  824. mmx_type:=mmxu16bit;
  825. s16bit:
  826. mmx_type:=mmxs16bit;
  827. u32bit:
  828. mmx_type:=mmxu32bit;
  829. s32bit:
  830. mmx_type:=mmxs32bit;
  831. end;
  832. end;
  833. end;
  834. function is_vector(p : tdef) : boolean;
  835. begin
  836. result:=(p.typ=arraydef) and
  837. not(is_special_array(p)) and
  838. (tarraydef(p).elementdef.typ=floatdef) and
  839. (tfloatdef(tarraydef(p).elementdef).floattype in [s32real,s64real]);
  840. end;
  841. { returns if the passed type (array) fits into an mm register }
  842. function fits_in_mm_register(p : tdef) : boolean;
  843. begin
  844. {$ifdef x86}
  845. result:= is_vector(p) and
  846. (
  847. (tarraydef(p).elementdef.typ=floatdef) and
  848. (
  849. (tarraydef(p).lowrange=0) and
  850. (tarraydef(p).highrange=3) and
  851. (tfloatdef(tarraydef(p).elementdef).floattype=s32real)
  852. )
  853. ) or
  854. (
  855. (tarraydef(p).elementdef.typ=floatdef) and
  856. (
  857. (tarraydef(p).lowrange=0) and
  858. (tarraydef(p).highrange=1) and
  859. (tfloatdef(tarraydef(p).elementdef).floattype=s64real)
  860. )
  861. );
  862. {$else x86}
  863. result:=false;
  864. {$endif x86}
  865. end;
  866. function is_mmx_able_array(p : tdef) : boolean;
  867. begin
  868. {$ifdef SUPPORT_MMX}
  869. if (cs_mmx_saturation in current_settings.localswitches) then
  870. begin
  871. is_mmx_able_array:=(p.typ=arraydef) and
  872. not(is_special_array(p)) and
  873. (
  874. (
  875. (tarraydef(p).elementdef.typ=orddef) and
  876. (
  877. (
  878. (tarraydef(p).lowrange=0) and
  879. (tarraydef(p).highrange=1) and
  880. (torddef(tarraydef(p).elementdef).ordtype in [u32bit,s32bit])
  881. )
  882. or
  883. (
  884. (tarraydef(p).lowrange=0) and
  885. (tarraydef(p).highrange=3) and
  886. (torddef(tarraydef(p).elementdef).ordtype in [u16bit,s16bit])
  887. )
  888. )
  889. )
  890. or
  891. (
  892. (
  893. (tarraydef(p).elementdef.typ=floatdef) and
  894. (
  895. (tarraydef(p).lowrange=0) and
  896. (tarraydef(p).highrange=1) and
  897. (tfloatdef(tarraydef(p).elementdef).floattype=s32real)
  898. )
  899. )
  900. )
  901. );
  902. end
  903. else
  904. begin
  905. is_mmx_able_array:=(p.typ=arraydef) and
  906. (
  907. (
  908. (tarraydef(p).elementdef.typ=orddef) and
  909. (
  910. (
  911. (tarraydef(p).lowrange=0) and
  912. (tarraydef(p).highrange=1) and
  913. (torddef(tarraydef(p).elementdef).ordtype in [u32bit,s32bit])
  914. )
  915. or
  916. (
  917. (tarraydef(p).lowrange=0) and
  918. (tarraydef(p).highrange=3) and
  919. (torddef(tarraydef(p).elementdef).ordtype in [u16bit,s16bit])
  920. )
  921. or
  922. (
  923. (tarraydef(p).lowrange=0) and
  924. (tarraydef(p).highrange=7) and
  925. (torddef(tarraydef(p).elementdef).ordtype in [u8bit,s8bit])
  926. )
  927. )
  928. )
  929. or
  930. (
  931. (tarraydef(p).elementdef.typ=floatdef) and
  932. (
  933. (tarraydef(p).lowrange=0) and
  934. (tarraydef(p).highrange=1) and
  935. (tfloatdef(tarraydef(p).elementdef).floattype=s32real)
  936. )
  937. )
  938. );
  939. end;
  940. {$else SUPPORT_MMX}
  941. is_mmx_able_array:=false;
  942. {$endif SUPPORT_MMX}
  943. end;
  944. function def_cgsize(def: tdef): tcgsize;
  945. begin
  946. case def.typ of
  947. orddef,
  948. enumdef,
  949. setdef:
  950. begin
  951. result:=int_cgsize(def.size);
  952. if is_signed(def) then
  953. result:=tcgsize(ord(result)+(ord(OS_S8)-ord(OS_8)));
  954. end;
  955. classrefdef,
  956. pointerdef:
  957. begin
  958. {$ifdef x86}
  959. if (def.typ=pointerdef) and
  960. (tpointerdef(def).x86pointertyp in [x86pt_far,x86pt_huge]) then
  961. begin
  962. {$if defined(i8086)}
  963. result := OS_32;
  964. {$elseif defined(i386)}
  965. internalerror(2013052201); { there's no OS_48 }
  966. {$elseif defined(x86_64)}
  967. internalerror(2013052202); { there's no OS_80 }
  968. {$endif}
  969. end
  970. else
  971. {$endif x86}
  972. result := OS_ADDR;
  973. end;
  974. procvardef:
  975. begin
  976. if not tprocvardef(def).is_addressonly then
  977. {$if sizeof(pint) = 2}
  978. result:=OS_32
  979. {$elseif sizeof(pint) = 4}
  980. result:=OS_64
  981. {$elseif sizeof(pint) = 8}
  982. result:=OS_128
  983. {$else}
  984. internalerror(200707141)
  985. {$endif}
  986. else
  987. result:=OS_ADDR;
  988. end;
  989. stringdef :
  990. begin
  991. if is_ansistring(def) or is_wide_or_unicode_string(def) then
  992. result := OS_ADDR
  993. else
  994. result:=int_cgsize(def.size);
  995. end;
  996. objectdef :
  997. begin
  998. if is_implicit_pointer_object_type(def) then
  999. result := OS_ADDR
  1000. else
  1001. result:=int_cgsize(def.size);
  1002. end;
  1003. floatdef:
  1004. if cs_fp_emulation in current_settings.moduleswitches then
  1005. result:=int_cgsize(def.size)
  1006. else
  1007. result:=tfloat2tcgsize[tfloatdef(def).floattype];
  1008. recorddef :
  1009. result:=int_cgsize(def.size);
  1010. arraydef :
  1011. begin
  1012. if not is_special_array(def) then
  1013. result := int_cgsize(def.size)
  1014. else
  1015. begin
  1016. if is_dynamic_array(def) then
  1017. result := OS_ADDR
  1018. else
  1019. result := OS_NO;
  1020. end;
  1021. end;
  1022. else
  1023. begin
  1024. { undefined size }
  1025. result:=OS_NO;
  1026. end;
  1027. end;
  1028. end;
  1029. function cgsize_orddef(size: tcgsize): torddef;
  1030. begin
  1031. case size of
  1032. OS_8:
  1033. result:=torddef(u8inttype);
  1034. OS_S8:
  1035. result:=torddef(s8inttype);
  1036. OS_16:
  1037. result:=torddef(u16inttype);
  1038. OS_S16:
  1039. result:=torddef(s16inttype);
  1040. OS_32:
  1041. result:=torddef(u32inttype);
  1042. OS_S32:
  1043. result:=torddef(s32inttype);
  1044. OS_64:
  1045. result:=torddef(u64inttype);
  1046. OS_S64:
  1047. result:=torddef(s64inttype);
  1048. else
  1049. internalerror(2012050401);
  1050. end;
  1051. end;
  1052. { In Windows 95 era, ordinals were restricted to [u8bit,s32bit,s16bit,bool16bit]
  1053. As of today, both signed and unsigned types from 8 to 64 bits are supported. }
  1054. function is_automatable(p : tdef) : boolean;
  1055. begin
  1056. result:=false;
  1057. case p.typ of
  1058. orddef:
  1059. result:=torddef(p).ordtype in [u8bit,s8bit,u16bit,s16bit,u32bit,s32bit,
  1060. u64bit,s64bit,bool16bit,scurrency];
  1061. floatdef:
  1062. result:=tfloatdef(p).floattype in [s64currency,s64real,s32real];
  1063. stringdef:
  1064. result:=tstringdef(p).stringtype in [st_ansistring,st_widestring,st_unicodestring];
  1065. variantdef:
  1066. result:=true;
  1067. objectdef:
  1068. result:=tobjectdef(p).objecttype in [odt_interfacecom,odt_dispinterface,odt_interfacecorba];
  1069. end;
  1070. end;
  1071. {# returns true, if the type passed is a varset }
  1072. function is_smallset(p : tdef) : boolean;
  1073. begin
  1074. {$if defined(cpu8bitalu)}
  1075. result:=(p.typ=setdef) and (p.size = 1)
  1076. {$elseif defined(cpu16bitalu)}
  1077. result:=(p.typ=setdef) and (p.size in [1,2])
  1078. {$else}
  1079. result:=(p.typ=setdef) and (p.size in [1,2,4])
  1080. {$endif}
  1081. end;
  1082. function is_bareprocdef(pd : tprocdef): boolean;
  1083. begin
  1084. result:=(pd.maxparacount=0) and
  1085. (is_void(pd.returndef) or
  1086. (pd.proctypeoption = potype_constructor));
  1087. end;
  1088. function get_common_intdef(ld, rd: torddef; keep_sign_if_equal: boolean): torddef;
  1089. var
  1090. llow, lhigh: tconstexprint;
  1091. begin
  1092. llow:=min(ld.low,rd.low);
  1093. lhigh:=max(ld.high,rd.high);
  1094. case range_to_basetype(llow,lhigh) of
  1095. s8bit:
  1096. result:=torddef(s8inttype);
  1097. u8bit:
  1098. result:=torddef(u8inttype);
  1099. s16bit:
  1100. result:=torddef(s16inttype);
  1101. u16bit:
  1102. result:=torddef(u16inttype);
  1103. s32bit:
  1104. result:=torddef(s32inttype);
  1105. u32bit:
  1106. result:=torddef(u32inttype);
  1107. s64bit:
  1108. result:=torddef(s64inttype);
  1109. u64bit:
  1110. result:=torddef(u64inttype);
  1111. else
  1112. begin
  1113. { avoid warning }
  1114. result:=nil;
  1115. internalerror(200802291);
  1116. end;
  1117. end;
  1118. if keep_sign_if_equal and
  1119. (is_signed(ld)=is_signed(rd)) and
  1120. (is_signed(result)<>is_signed(ld)) then
  1121. case result.ordtype of
  1122. s8bit:
  1123. result:=torddef(u8inttype);
  1124. u8bit:
  1125. result:=torddef(s16inttype);
  1126. s16bit:
  1127. result:=torddef(u16inttype);
  1128. u16bit:
  1129. result:=torddef(s32inttype);
  1130. s32bit:
  1131. result:=torddef(u32inttype);
  1132. u32bit:
  1133. result:=torddef(s64inttype);
  1134. s64bit:
  1135. result:=torddef(u64inttype);
  1136. end;
  1137. end;
  1138. function is_valid_univ_para_type(def: tdef): boolean;
  1139. begin
  1140. result:=
  1141. not is_open_array(def) and
  1142. not is_void(def) and
  1143. (def.typ<>formaldef);
  1144. end;
  1145. function is_nested_pd(def: tabstractprocdef): boolean;{$ifdef USEINLINE}inline;{$endif}
  1146. begin
  1147. result:=def.parast.symtablelevel>normal_function_level;
  1148. end;
  1149. function is_typeparam(def : tdef) : boolean;{$ifdef USEINLINE}inline;{$endif}
  1150. begin
  1151. result:=(def.typ=undefineddef);
  1152. end;
  1153. function is_methodpointer(def: tdef): boolean;
  1154. begin
  1155. result:=(def.typ=procvardef) and (po_methodpointer in tprocvardef(def).procoptions);
  1156. end;
  1157. end.