defbase.pas 72 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. This unit provides some help routines for type handling
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit defbase;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. cclasses,
  23. cpuinfo,
  24. globals,
  25. node,
  26. symconst,symbase,symtype,symdef,symsym;
  27. type
  28. tmmxtype = (mmxno,mmxu8bit,mmxs8bit,mmxu16bit,mmxs16bit,
  29. mmxu32bit,mmxs32bit,mmxfixed16,mmxsingle);
  30. const
  31. {# true if we must never copy this parameter }
  32. never_copy_const_param : boolean = false;
  33. {*****************************************************************************
  34. Basic type functions
  35. *****************************************************************************}
  36. {# Returns true, if def defines an ordinal type }
  37. function is_ordinal(def : tdef) : boolean;
  38. {# Returns the min. value of the type }
  39. function get_min_value(def : tdef) : TConstExprInt;
  40. {# Returns basetype of the specified range }
  41. function range_to_basetype(low,high:TConstExprInt):tbasetype;
  42. {# Returns true, if def defines an ordinal type }
  43. function is_integer(def : tdef) : boolean;
  44. {# Returns true if p is a boolean }
  45. function is_boolean(def : tdef) : boolean;
  46. {# Returns true if p is a char }
  47. function is_char(def : tdef) : boolean;
  48. {# Returns true if p is a widechar }
  49. function is_widechar(def : tdef) : boolean;
  50. {# Returns true if p is a void}
  51. function is_void(def : tdef) : boolean;
  52. {# Returns true if p is a smallset def }
  53. function is_smallset(p : tdef) : boolean;
  54. {# Returns true, if def defines a signed data type (only for ordinal types) }
  55. function is_signed(def : tdef) : boolean;
  56. {# Returns true whether def_from's range is comprised in def_to's if both are
  57. orddefs, false otherwise }
  58. function is_in_limit(def_from,def_to : tdef) : boolean;
  59. {*****************************************************************************
  60. Array helper functions
  61. *****************************************************************************}
  62. {# Returns true, if p points to a zero based (non special like open or
  63. dynamic array def).
  64. This is mainly used to see if the array
  65. is convertable to a pointer
  66. }
  67. function is_zero_based_array(p : tdef) : boolean;
  68. {# Returns true if p points to an open array def }
  69. function is_open_array(p : tdef) : boolean;
  70. {# Returns true if p points to a dynamic array def }
  71. function is_dynamic_array(p : tdef) : boolean;
  72. {# Returns true, if p points to an array of const def }
  73. function is_array_constructor(p : tdef) : boolean;
  74. {# Returns true, if p points to a variant array }
  75. function is_variant_array(p : tdef) : boolean;
  76. {# Returns true, if p points to an array of const }
  77. function is_array_of_const(p : tdef) : boolean;
  78. {# Returns true, if p points any kind of special array
  79. That is if the array is an open array, a variant
  80. array, an array constants constructor, or an
  81. array of const.
  82. }
  83. function is_special_array(p : tdef) : boolean;
  84. {# Returns true if p is a char array def }
  85. function is_chararray(p : tdef) : boolean;
  86. {# Returns true if p is a wide char array def }
  87. function is_widechararray(p : tdef) : boolean;
  88. {*****************************************************************************
  89. String helper functions
  90. *****************************************************************************}
  91. {# Returns true if p points to an open string def }
  92. function is_open_string(p : tdef) : boolean;
  93. {# Returns true if p is an ansi string def }
  94. function is_ansistring(p : tdef) : boolean;
  95. {# Returns true if p is a long string def }
  96. function is_longstring(p : tdef) : boolean;
  97. {# returns true if p is a wide string def }
  98. function is_widestring(p : tdef) : boolean;
  99. {# Returns true if p is a short string def }
  100. function is_shortstring(p : tdef) : boolean;
  101. {# Returns true if p is a pchar def }
  102. function is_pchar(p : tdef) : boolean;
  103. {# Returns true if p is a pwidechar def }
  104. function is_pwidechar(p : tdef) : boolean;
  105. {# Returns true if p is a voidpointer def }
  106. function is_voidpointer(p : tdef) : boolean;
  107. {# Returns true, if definition is float }
  108. function is_fpu(def : tdef) : boolean;
  109. {# Returns true, if def is a currency type }
  110. function is_currency(def : tdef) : boolean;
  111. {# Returns true, if def is a 64 bit integer type }
  112. function is_64bitint(def : tdef) : boolean;
  113. {# Returns true, if def1 and def2 are semantically the same }
  114. function is_equal(def1,def2 : tdef) : boolean;
  115. {# Checks for type compatibility (subgroups of type)
  116. used for case statements... probably missing stuff
  117. to use on other types
  118. }
  119. function is_subequal(def1, def2: tdef): boolean;
  120. type
  121. tconverttype = (
  122. tc_equal,
  123. tc_not_possible,
  124. tc_string_2_string,
  125. tc_char_2_string,
  126. tc_char_2_chararray,
  127. tc_pchar_2_string,
  128. tc_cchar_2_pchar,
  129. tc_cstring_2_pchar,
  130. tc_ansistring_2_pchar,
  131. tc_string_2_chararray,
  132. tc_chararray_2_string,
  133. tc_array_2_pointer,
  134. tc_pointer_2_array,
  135. tc_int_2_int,
  136. tc_int_2_bool,
  137. tc_bool_2_bool,
  138. tc_bool_2_int,
  139. tc_real_2_real,
  140. tc_int_2_real,
  141. tc_proc_2_procvar,
  142. tc_arrayconstructor_2_set,
  143. tc_load_smallset,
  144. tc_cord_2_pointer,
  145. tc_intf_2_string,
  146. tc_intf_2_guid,
  147. tc_class_2_intf,
  148. tc_char_2_char,
  149. tc_normal_2_smallset,
  150. tc_dynarray_2_openarray
  151. );
  152. function assignment_overloaded(from_def,to_def : tdef) : tprocdef;
  153. { Returns:
  154. 0 - Not convertable
  155. 1 - Convertable
  156. 2 - Convertable, but not first choice }
  157. function isconvertable(def_from,def_to : tdef;
  158. var doconv : tconverttype;
  159. fromtreetype : tnodetype;
  160. explicit : boolean) : byte;
  161. { Same as is_equal, but with error message if failed }
  162. function CheckTypes(def1,def2 : tdef) : boolean;
  163. function equal_constsym(sym1,sym2:tconstsym):boolean;
  164. {# true, if two parameter lists are equal
  165. if acp is cp_none, all have to match exactly
  166. if acp is cp_value_equal_const call by value
  167. and call by const parameter are assumed as
  168. equal
  169. }
  170. { if acp is cp_all the var const or nothing are considered equal }
  171. type
  172. compare_type = ( cp_none, cp_value_equal_const, cp_all);
  173. function equal_paras(paralist1,paralist2 : tlinkedlist; acp : compare_type) : boolean;
  174. { True if a type can be allowed for another one
  175. in a func var }
  176. function convertable_paras(paralist1,paralist2 : tlinkedlist; acp : compare_type) : boolean;
  177. { True if a function can be assigned to a procvar }
  178. { changed first argument type to pabstractprocdef so that it can also be }
  179. { used to test compatibility between two pprocvardefs (JM) }
  180. function proc_to_procvar_equal(def1:tabstractprocdef;def2:tprocvardef;exact:boolean) : boolean;
  181. function get_proc_2_procvar_def(p:tprocsym;d:tprocvardef):tprocdef;
  182. {# If @var(l) isn't in the range of def a range check error (if not explicit) is generated and
  183. the value is placed within the range
  184. }
  185. procedure testrange(def : tdef;var l : tconstexprint;explicit:boolean);
  186. {# Returns the range of def, where @var(l) is the low-range and @var(h) is
  187. the high-range.
  188. }
  189. procedure getrange(def : tdef;var l : TConstExprInt;var h : TConstExprInt);
  190. { some type helper routines for MMX support }
  191. function is_mmx_able_array(p : tdef) : boolean;
  192. {# returns the mmx type }
  193. function mmx_type(p : tdef) : tmmxtype;
  194. {# returns true, if sym needs an entry in the proplist of a class rtti }
  195. function needs_prop_entry(sym : tsym) : boolean;
  196. implementation
  197. uses
  198. globtype,tokens,verbose,
  199. symtable;
  200. function needs_prop_entry(sym : tsym) : boolean;
  201. begin
  202. needs_prop_entry:=(sp_published in tsym(sym).symoptions) and
  203. (sym.typ in [propertysym,varsym]);
  204. end;
  205. function equal_constsym(sym1,sym2:tconstsym):boolean;
  206. var
  207. p1,p2,pend : pchar;
  208. begin
  209. equal_constsym:=false;
  210. if sym1.consttyp<>sym2.consttyp then
  211. exit;
  212. case sym1.consttyp of
  213. constint,
  214. constbool,
  215. constchar,
  216. constord :
  217. equal_constsym:=(sym1.valueord=sym2.valueord);
  218. constpointer :
  219. equal_constsym:=(sym1.valueordptr=sym2.valueordptr);
  220. conststring,constresourcestring :
  221. begin
  222. if sym1.len=sym2.len then
  223. begin
  224. p1:=pchar(sym1.valueptr);
  225. p2:=pchar(sym2.valueptr);
  226. pend:=p1+sym1.len;
  227. while (p1<pend) do
  228. begin
  229. if p1^<>p2^ then
  230. break;
  231. inc(p1);
  232. inc(p2);
  233. end;
  234. if (p1=pend) then
  235. equal_constsym:=true;
  236. end;
  237. end;
  238. constreal :
  239. equal_constsym:=(pbestreal(sym1.valueptr)^=pbestreal(sym2.valueptr)^);
  240. constset :
  241. equal_constsym:=(pnormalset(sym1.valueptr)^=pnormalset(sym2.valueptr)^);
  242. constnil :
  243. equal_constsym:=true;
  244. end;
  245. end;
  246. { compare_type = ( cp_none, cp_value_equal_const, cp_all); }
  247. function equal_paras(paralist1,paralist2 : TLinkedList; acp : compare_type) : boolean;
  248. var
  249. def1,def2 : TParaItem;
  250. begin
  251. def1:=TParaItem(paralist1.first);
  252. def2:=TParaItem(paralist2.first);
  253. while (assigned(def1)) and (assigned(def2)) do
  254. begin
  255. case acp of
  256. cp_value_equal_const :
  257. begin
  258. if not(is_equal(def1.paratype.def,def2.paratype.def)) or
  259. ((def1.paratyp<>def2.paratyp) and
  260. ((def1.paratyp in [vs_var,vs_out]) or
  261. (def2.paratyp in [vs_var,vs_out])
  262. )
  263. ) then
  264. begin
  265. equal_paras:=false;
  266. exit;
  267. end;
  268. end;
  269. cp_all :
  270. begin
  271. if not(is_equal(def1.paratype.def,def2.paratype.def)) or
  272. (def1.paratyp<>def2.paratyp) then
  273. begin
  274. equal_paras:=false;
  275. exit;
  276. end;
  277. end;
  278. cp_none :
  279. begin
  280. if not(is_equal(def1.paratype.def,def2.paratype.def)) then
  281. begin
  282. equal_paras:=false;
  283. exit;
  284. end;
  285. { also check default value if both have it declared }
  286. if assigned(def1.defaultvalue) and
  287. assigned(def2.defaultvalue) then
  288. begin
  289. if not equal_constsym(tconstsym(def1.defaultvalue),tconstsym(def2.defaultvalue)) then
  290. begin
  291. equal_paras:=false;
  292. exit;
  293. end;
  294. end;
  295. end;
  296. end;
  297. def1:=TParaItem(def1.next);
  298. def2:=TParaItem(def2.next);
  299. end;
  300. if (def1=nil) and (def2=nil) then
  301. equal_paras:=true
  302. else
  303. equal_paras:=false;
  304. end;
  305. function convertable_paras(paralist1,paralist2 : TLinkedList;acp : compare_type) : boolean;
  306. var
  307. def1,def2 : TParaItem;
  308. doconv : tconverttype;
  309. begin
  310. def1:=TParaItem(paralist1.first);
  311. def2:=TParaItem(paralist2.first);
  312. while (assigned(def1)) and (assigned(def2)) do
  313. begin
  314. case acp of
  315. cp_value_equal_const :
  316. begin
  317. if (isconvertable(def1.paratype.def,def2.paratype.def,doconv,callparan,false)=0) or
  318. ((def1.paratyp<>def2.paratyp) and
  319. ((def1.paratyp in [vs_out,vs_var]) or
  320. (def2.paratyp in [vs_out,vs_var])
  321. )
  322. ) then
  323. begin
  324. convertable_paras:=false;
  325. exit;
  326. end;
  327. end;
  328. cp_all :
  329. begin
  330. if (isconvertable(def1.paratype.def,def2.paratype.def,doconv,callparan,false)=0) or
  331. (def1.paratyp<>def2.paratyp) then
  332. begin
  333. convertable_paras:=false;
  334. exit;
  335. end;
  336. end;
  337. cp_none :
  338. begin
  339. if (isconvertable(def1.paratype.def,def2.paratype.def,doconv,callparan,false)=0) then
  340. begin
  341. convertable_paras:=false;
  342. exit;
  343. end;
  344. end;
  345. end;
  346. def1:=TParaItem(def1.next);
  347. def2:=TParaItem(def2.next);
  348. end;
  349. if (def1=nil) and (def2=nil) then
  350. convertable_paras:=true
  351. else
  352. convertable_paras:=false;
  353. end;
  354. { true if a function can be assigned to a procvar }
  355. { changed first argument type to pabstractprocdef so that it can also be }
  356. { used to test compatibility between two pprocvardefs (JM) }
  357. function proc_to_procvar_equal(def1:tabstractprocdef;def2:tprocvardef;exact:boolean) : boolean;
  358. const
  359. po_comp = po_compatibility_options-[po_methodpointer,po_classmethod];
  360. var
  361. ismethod : boolean;
  362. begin
  363. proc_to_procvar_equal:=false;
  364. if not(assigned(def1)) or not(assigned(def2)) then
  365. exit;
  366. { check for method pointer }
  367. if def1.deftype=procvardef then
  368. begin
  369. ismethod:=(po_methodpointer in def1.procoptions);
  370. end
  371. else
  372. begin
  373. ismethod:=assigned(def1.owner) and
  374. (def1.owner.symtabletype=objectsymtable);
  375. end;
  376. if (ismethod and not (po_methodpointer in def2.procoptions)) or
  377. (not(ismethod) and (po_methodpointer in def2.procoptions)) then
  378. begin
  379. Message(type_e_no_method_and_procedure_not_compatible);
  380. exit;
  381. end;
  382. { check return value and para's and options, methodpointer is already checked
  383. parameters may also be convertable }
  384. if is_equal(def1.rettype.def,def2.rettype.def) and
  385. (equal_paras(def1.para,def2.para,cp_all) or
  386. ((not exact) and convertable_paras(def1.para,def2.para,cp_all))) and
  387. ((po_comp * def1.procoptions)= (po_comp * def2.procoptions)) then
  388. proc_to_procvar_equal:=true
  389. else
  390. proc_to_procvar_equal:=false;
  391. end;
  392. function get_proc_2_procvar_def(p:tprocsym;d:tprocvardef):tprocdef;
  393. var
  394. matchprocdef : tprocdef;
  395. pd : pprocdeflist;
  396. begin
  397. { This function will return the pprocdef of pprocsym that
  398. is the best match for procvardef. When there are multiple
  399. matches it returns nil }
  400. { exact match }
  401. matchprocdef:=nil;
  402. pd:=p.defs;
  403. while assigned(pd) do
  404. begin
  405. if proc_to_procvar_equal(pd^.def,d,true) then
  406. begin
  407. { already found a match ? Then stop and return nil }
  408. if assigned(matchprocdef) then
  409. begin
  410. matchprocdef:=nil;
  411. break;
  412. end;
  413. matchprocdef:=pd^.def;
  414. end;
  415. pd:=pd^.next;
  416. end;
  417. { convertable match, if no exact match was found }
  418. if not assigned(matchprocdef) and
  419. not assigned(pd) then
  420. begin
  421. pd:=p.defs;
  422. while assigned(pd) do
  423. begin
  424. if proc_to_procvar_equal(pd^.def,d,false) then
  425. begin
  426. { already found a match ? Then stop and return nil }
  427. if assigned(matchprocdef) then
  428. begin
  429. matchprocdef:=nil;
  430. break;
  431. end;
  432. matchprocdef:=pd^.def;
  433. end;
  434. pd:=pd^.next;
  435. end;
  436. end;
  437. get_proc_2_procvar_def:=matchprocdef;
  438. end;
  439. { returns true, if def uses FPU }
  440. function is_fpu(def : tdef) : boolean;
  441. begin
  442. is_fpu:=(def.deftype=floatdef);
  443. end;
  444. { returns true, if def is a currency type }
  445. function is_currency(def : tdef) : boolean;
  446. begin
  447. is_currency:=(def.deftype=floatdef) and (tfloatdef(def).typ=s64currency);
  448. end;
  449. function range_to_basetype(low,high:TConstExprInt):tbasetype;
  450. begin
  451. { generate a unsigned range if high<0 and low>=0 }
  452. if (low>=0) and (high<0) then
  453. range_to_basetype:=u32bit
  454. else if (low>=0) and (high<=255) then
  455. range_to_basetype:=u8bit
  456. else if (low>=-128) and (high<=127) then
  457. range_to_basetype:=s8bit
  458. else if (low>=0) and (high<=65536) then
  459. range_to_basetype:=u16bit
  460. else if (low>=-32768) and (high<=32767) then
  461. range_to_basetype:=s16bit
  462. else
  463. range_to_basetype:=s32bit;
  464. end;
  465. { true if p is an ordinal }
  466. function is_ordinal(def : tdef) : boolean;
  467. var
  468. dt : tbasetype;
  469. begin
  470. case def.deftype of
  471. orddef :
  472. begin
  473. dt:=torddef(def).typ;
  474. is_ordinal:=dt in [uchar,uwidechar,
  475. u8bit,u16bit,u32bit,u64bit,
  476. s8bit,s16bit,s32bit,s64bit,
  477. bool8bit,bool16bit,bool32bit];
  478. end;
  479. enumdef :
  480. is_ordinal:=true;
  481. else
  482. is_ordinal:=false;
  483. end;
  484. end;
  485. { returns the min. value of the type }
  486. function get_min_value(def : tdef) : TConstExprInt;
  487. begin
  488. case def.deftype of
  489. orddef:
  490. get_min_value:=torddef(def).low;
  491. enumdef:
  492. get_min_value:=tenumdef(def).min;
  493. else
  494. get_min_value:=0;
  495. end;
  496. end;
  497. { true if p is an integer }
  498. function is_integer(def : tdef) : boolean;
  499. begin
  500. is_integer:=(def.deftype=orddef) and
  501. (torddef(def).typ in [u8bit,u16bit,u32bit,u64bit,
  502. s8bit,s16bit,s32bit,s64bit]);
  503. end;
  504. { true if p is a boolean }
  505. function is_boolean(def : tdef) : boolean;
  506. begin
  507. is_boolean:=(def.deftype=orddef) and
  508. (torddef(def).typ in [bool8bit,bool16bit,bool32bit]);
  509. end;
  510. { true if p is a void }
  511. function is_void(def : tdef) : boolean;
  512. begin
  513. is_void:=(def.deftype=orddef) and
  514. (torddef(def).typ=uvoid);
  515. end;
  516. { true if p is a char }
  517. function is_char(def : tdef) : boolean;
  518. begin
  519. is_char:=(def.deftype=orddef) and
  520. (torddef(def).typ=uchar);
  521. end;
  522. { true if p is a wchar }
  523. function is_widechar(def : tdef) : boolean;
  524. begin
  525. is_widechar:=(def.deftype=orddef) and
  526. (torddef(def).typ=uwidechar);
  527. end;
  528. { true if p is signed (integer) }
  529. function is_signed(def : tdef) : boolean;
  530. var
  531. dt : tbasetype;
  532. begin
  533. case def.deftype of
  534. orddef :
  535. begin
  536. dt:=torddef(def).typ;
  537. is_signed:=(dt in [s8bit,s16bit,s32bit,s64bit]);
  538. end;
  539. enumdef :
  540. is_signed:=tenumdef(def).min < 0;
  541. arraydef :
  542. is_signed:=is_signed(tarraydef(def).rangetype.def);
  543. else
  544. is_signed:=false;
  545. end;
  546. end;
  547. function is_in_limit(def_from,def_to : tdef) : boolean;
  548. var
  549. fromqword, toqword: boolean;
  550. begin
  551. if (def_from.deftype <> orddef) or
  552. (def_to.deftype <> orddef) then
  553. begin
  554. is_in_limit := false;
  555. exit;
  556. end;
  557. fromqword := torddef(def_from).typ = u64bit;
  558. toqword := torddef(def_to).typ = u64bit;
  559. is_in_limit:=((not(fromqword xor toqword) and
  560. (torddef(def_from).low>=torddef(def_to).low) and
  561. (torddef(def_from).high<=torddef(def_to).high)) or
  562. (toqword and not is_signed(def_from)));
  563. end;
  564. { true, if p points to an open array def }
  565. function is_open_string(p : tdef) : boolean;
  566. begin
  567. is_open_string:=(p.deftype=stringdef) and
  568. (tstringdef(p).string_typ=st_shortstring) and
  569. (tstringdef(p).len=0);
  570. end;
  571. { true, if p points to a zero based array def }
  572. function is_zero_based_array(p : tdef) : boolean;
  573. begin
  574. is_zero_based_array:=(p.deftype=arraydef) and
  575. (tarraydef(p).lowrange=0) and
  576. not(is_special_array(p));
  577. end;
  578. { true if p points to a dynamic array def }
  579. function is_dynamic_array(p : tdef) : boolean;
  580. begin
  581. is_dynamic_array:=(p.deftype=arraydef) and
  582. tarraydef(p).IsDynamicArray;
  583. end;
  584. { true, if p points to an open array def }
  585. function is_open_array(p : tdef) : boolean;
  586. begin
  587. { check for s32bittype is needed, because for u32bit the high
  588. range is also -1 ! (PFV) }
  589. is_open_array:=(p.deftype=arraydef) and
  590. (tarraydef(p).rangetype.def=s32bittype.def) and
  591. (tarraydef(p).lowrange=0) and
  592. (tarraydef(p).highrange=-1) and
  593. not(tarraydef(p).IsConstructor) and
  594. not(tarraydef(p).IsVariant) and
  595. not(tarraydef(p).IsArrayOfConst) and
  596. not(tarraydef(p).IsDynamicArray);
  597. end;
  598. { true, if p points to an array of const def }
  599. function is_array_constructor(p : tdef) : boolean;
  600. begin
  601. is_array_constructor:=(p.deftype=arraydef) and
  602. (tarraydef(p).IsConstructor);
  603. end;
  604. { true, if p points to a variant array }
  605. function is_variant_array(p : tdef) : boolean;
  606. begin
  607. is_variant_array:=(p.deftype=arraydef) and
  608. (tarraydef(p).IsVariant);
  609. end;
  610. { true, if p points to an array of const }
  611. function is_array_of_const(p : tdef) : boolean;
  612. begin
  613. is_array_of_const:=(p.deftype=arraydef) and
  614. (tarraydef(p).IsArrayOfConst);
  615. end;
  616. { true, if p points to a special array }
  617. function is_special_array(p : tdef) : boolean;
  618. begin
  619. is_special_array:=(p.deftype=arraydef) and
  620. ((tarraydef(p).IsVariant) or
  621. (tarraydef(p).IsArrayOfConst) or
  622. (tarraydef(p).IsConstructor) or
  623. is_open_array(p)
  624. );
  625. end;
  626. { true if p is an ansi string def }
  627. function is_ansistring(p : tdef) : boolean;
  628. begin
  629. is_ansistring:=(p.deftype=stringdef) and
  630. (tstringdef(p).string_typ=st_ansistring);
  631. end;
  632. { true if p is an long string def }
  633. function is_longstring(p : tdef) : boolean;
  634. begin
  635. is_longstring:=(p.deftype=stringdef) and
  636. (tstringdef(p).string_typ=st_longstring);
  637. end;
  638. { true if p is an wide string def }
  639. function is_widestring(p : tdef) : boolean;
  640. begin
  641. is_widestring:=(p.deftype=stringdef) and
  642. (tstringdef(p).string_typ=st_widestring);
  643. end;
  644. { true if p is an short string def }
  645. function is_shortstring(p : tdef) : boolean;
  646. begin
  647. is_shortstring:=(p.deftype=stringdef) and
  648. (tstringdef(p).string_typ=st_shortstring);
  649. end;
  650. { true if p is a char array def }
  651. function is_chararray(p : tdef) : boolean;
  652. begin
  653. is_chararray:=(p.deftype=arraydef) and
  654. is_equal(tarraydef(p).elementtype.def,cchartype.def) and
  655. not(is_special_array(p));
  656. end;
  657. { true if p is a widechar array def }
  658. function is_widechararray(p : tdef) : boolean;
  659. begin
  660. is_widechararray:=(p.deftype=arraydef) and
  661. is_equal(tarraydef(p).elementtype.def,cwidechartype.def) and
  662. not(is_special_array(p));
  663. end;
  664. { true if p is a pchar def }
  665. function is_pchar(p : tdef) : boolean;
  666. begin
  667. is_pchar:=(p.deftype=pointerdef) and
  668. (is_equal(tpointerdef(p).pointertype.def,cchartype.def) or
  669. (is_zero_based_array(tpointerdef(p).pointertype.def) and
  670. is_chararray(tpointerdef(p).pointertype.def)));
  671. end;
  672. { true if p is a pchar def }
  673. function is_pwidechar(p : tdef) : boolean;
  674. begin
  675. is_pwidechar:=(p.deftype=pointerdef) and
  676. (is_equal(tpointerdef(p).pointertype.def,cwidechartype.def) or
  677. (is_zero_based_array(tpointerdef(p).pointertype.def) and
  678. is_widechararray(tpointerdef(p).pointertype.def)));
  679. end;
  680. { true if p is a voidpointer def }
  681. function is_voidpointer(p : tdef) : boolean;
  682. begin
  683. is_voidpointer:=(p.deftype=pointerdef) and
  684. (tpointerdef(p).pointertype.def.deftype=orddef) and
  685. (torddef(tpointerdef(p).pointertype.def).typ=uvoid);
  686. end;
  687. { true if p is a smallset def }
  688. function is_smallset(p : tdef) : boolean;
  689. begin
  690. is_smallset:=(p.deftype=setdef) and
  691. (tsetdef(p).settype=smallset);
  692. end;
  693. { true, if def is a 64 bit int type }
  694. function is_64bitint(def : tdef) : boolean;
  695. begin
  696. is_64bitint:=(def.deftype=orddef) and (torddef(def).typ in [u64bit,s64bit])
  697. end;
  698. { if l isn't in the range of def a range check error (if not explicit) is generated and
  699. the value is placed within the range }
  700. procedure testrange(def : tdef;var l : tconstexprint;explicit:boolean);
  701. var
  702. lv,hv: TConstExprInt;
  703. error: boolean;
  704. begin
  705. error := false;
  706. { for 64 bit types we need only to check if it is less than }
  707. { zero, if def is a qword node }
  708. if is_64bitint(def) then
  709. begin
  710. if (l<0) and (torddef(def).typ=u64bit) then
  711. begin
  712. { don't zero the result, because it may come from hex notation
  713. like $ffffffffffffffff! (JM)
  714. l:=0; }
  715. if not explicit then
  716. begin
  717. if (cs_check_range in aktlocalswitches) then
  718. Message(parser_e_range_check_error)
  719. else
  720. Message(parser_w_range_check_error);
  721. end;
  722. error := true;
  723. end;
  724. end
  725. else
  726. begin
  727. getrange(def,lv,hv);
  728. if (def.deftype=orddef) and
  729. (torddef(def).typ=u32bit) then
  730. begin
  731. if (l < cardinal(lv)) or
  732. (l > cardinal(hv)) then
  733. begin
  734. if not explicit then
  735. begin
  736. if (cs_check_range in aktlocalswitches) then
  737. Message(parser_e_range_check_error)
  738. else
  739. Message(parser_w_range_check_error);
  740. end;
  741. error := true;
  742. end;
  743. end
  744. else if (l<lv) or (l>hv) then
  745. begin
  746. if not explicit then
  747. begin
  748. if ((def.deftype=enumdef) and
  749. { delphi allows range check errors in
  750. enumeration type casts FK }
  751. not(m_delphi in aktmodeswitches)) or
  752. (cs_check_range in aktlocalswitches) then
  753. Message(parser_e_range_check_error)
  754. else
  755. Message(parser_w_range_check_error);
  756. end;
  757. error := true;
  758. end;
  759. end;
  760. if error then
  761. begin
  762. { Fix the value to fit in the allocated space for this type of variable }
  763. case def.size of
  764. 1: l := l and $ff;
  765. 2: l := l and $ffff;
  766. { work around sign extension bug (to be fixed) (JM) }
  767. 4: l := l and (int64($fffffff) shl 4 + $f);
  768. end;
  769. { do sign extension if necessary (JM) }
  770. if is_signed(def) then
  771. begin
  772. case def.size of
  773. 1: l := shortint(l);
  774. 2: l := smallint(l);
  775. 4: l := longint(l);
  776. end;
  777. end;
  778. end;
  779. end;
  780. { return the range from def in l and h }
  781. procedure getrange(def : tdef;var l : TConstExprInt;var h : TConstExprInt);
  782. begin
  783. case def.deftype of
  784. orddef :
  785. begin
  786. l:=torddef(def).low;
  787. h:=torddef(def).high;
  788. end;
  789. enumdef :
  790. begin
  791. l:=tenumdef(def).min;
  792. h:=tenumdef(def).max;
  793. end;
  794. arraydef :
  795. begin
  796. l:=tarraydef(def).lowrange;
  797. h:=tarraydef(def).highrange;
  798. end;
  799. else
  800. internalerror(987);
  801. end;
  802. end;
  803. function mmx_type(p : tdef) : tmmxtype;
  804. begin
  805. mmx_type:=mmxno;
  806. if is_mmx_able_array(p) then
  807. begin
  808. if tarraydef(p).elementtype.def.deftype=floatdef then
  809. case tfloatdef(tarraydef(p).elementtype.def).typ of
  810. s32real:
  811. mmx_type:=mmxsingle;
  812. end
  813. else
  814. case torddef(tarraydef(p).elementtype.def).typ of
  815. u8bit:
  816. mmx_type:=mmxu8bit;
  817. s8bit:
  818. mmx_type:=mmxs8bit;
  819. u16bit:
  820. mmx_type:=mmxu16bit;
  821. s16bit:
  822. mmx_type:=mmxs16bit;
  823. u32bit:
  824. mmx_type:=mmxu32bit;
  825. s32bit:
  826. mmx_type:=mmxs32bit;
  827. end;
  828. end;
  829. end;
  830. function is_mmx_able_array(p : tdef) : boolean;
  831. begin
  832. {$ifdef SUPPORT_MMX}
  833. if (cs_mmx_saturation in aktlocalswitches) then
  834. begin
  835. is_mmx_able_array:=(p.deftype=arraydef) and
  836. not(is_special_array(p)) and
  837. (
  838. (
  839. (tarraydef(p).elementtype.def.deftype=orddef) and
  840. (
  841. (
  842. (tarraydef(p).lowrange=0) and
  843. (tarraydef(p).highrange=1) and
  844. (torddef(tarraydef(p).elementtype.def).typ in [u32bit,s32bit])
  845. )
  846. or
  847. (
  848. (tarraydef(p).lowrange=0) and
  849. (tarraydef(p).highrange=3) and
  850. (torddef(tarraydef(p).elementtype.def).typ in [u16bit,s16bit])
  851. )
  852. )
  853. )
  854. or
  855. (
  856. (
  857. (tarraydef(p).elementtype.def.deftype=floatdef) and
  858. (
  859. (tarraydef(p).lowrange=0) and
  860. (tarraydef(p).highrange=1) and
  861. (tfloatdef(tarraydef(p).elementtype.def).typ=s32real)
  862. )
  863. )
  864. )
  865. );
  866. end
  867. else
  868. begin
  869. is_mmx_able_array:=(p.deftype=arraydef) and
  870. (
  871. (
  872. (tarraydef(p).elementtype.def.deftype=orddef) and
  873. (
  874. (
  875. (tarraydef(p).lowrange=0) and
  876. (tarraydef(p).highrange=1) and
  877. (torddef(tarraydef(p).elementtype.def).typ in [u32bit,s32bit])
  878. )
  879. or
  880. (
  881. (tarraydef(p).lowrange=0) and
  882. (tarraydef(p).highrange=3) and
  883. (torddef(tarraydef(p).elementtype.def).typ in [u16bit,s16bit])
  884. )
  885. or
  886. (
  887. (tarraydef(p).lowrange=0) and
  888. (tarraydef(p).highrange=7) and
  889. (torddef(tarraydef(p).elementtype.def).typ in [u8bit,s8bit])
  890. )
  891. )
  892. )
  893. or
  894. (
  895. (tarraydef(p).elementtype.def.deftype=floatdef) and
  896. (
  897. (tarraydef(p).lowrange=0) and
  898. (tarraydef(p).highrange=1) and
  899. (tfloatdef(tarraydef(p).elementtype.def).typ=s32real)
  900. )
  901. )
  902. );
  903. end;
  904. {$else SUPPORT_MMX}
  905. is_mmx_able_array:=false;
  906. {$endif SUPPORT_MMX}
  907. end;
  908. function is_equal(def1,def2 : tdef) : boolean;
  909. var
  910. b : boolean;
  911. hd : tdef;
  912. begin
  913. { both types must exists }
  914. if not (assigned(def1) and assigned(def2)) then
  915. begin
  916. is_equal:=false;
  917. exit;
  918. end;
  919. { be sure, that if there is a stringdef, that this is def1 }
  920. if def2.deftype=stringdef then
  921. begin
  922. hd:=def1;
  923. def1:=def2;
  924. def2:=hd;
  925. end;
  926. b:=false;
  927. { both point to the same definition ? }
  928. if def1=def2 then
  929. b:=true
  930. else
  931. { pointer with an equal definition are equal }
  932. if (def1.deftype=pointerdef) and (def2.deftype=pointerdef) then
  933. begin
  934. { check if both are farpointer }
  935. if (tpointerdef(def1).is_far=tpointerdef(def2).is_far) then
  936. begin
  937. { here a problem detected in tabsolutesym }
  938. { the types can be forward type !! }
  939. if assigned(def1.typesym) and (tpointerdef(def1).pointertype.def.deftype=forwarddef) then
  940. b:=(def1.typesym=def2.typesym)
  941. else
  942. b:=tpointerdef(def1).pointertype.def=tpointerdef(def2).pointertype.def;
  943. end
  944. else
  945. b:=false;
  946. end
  947. else
  948. { ordinals are equal only when the ordinal type is equal }
  949. if (def1.deftype=orddef) and (def2.deftype=orddef) then
  950. begin
  951. case torddef(def1).typ of
  952. u8bit,u16bit,u32bit,
  953. s8bit,s16bit,s32bit:
  954. b:=((torddef(def1).typ=torddef(def2).typ) and
  955. (torddef(def1).low=torddef(def2).low) and
  956. (torddef(def1).high=torddef(def2).high));
  957. uvoid,uchar,uwidechar,
  958. bool8bit,bool16bit,bool32bit:
  959. b:=(torddef(def1).typ=torddef(def2).typ);
  960. end;
  961. end
  962. else
  963. if (def1.deftype=floatdef) and (def2.deftype=floatdef) then
  964. b:=tfloatdef(def1).typ=tfloatdef(def2).typ
  965. else
  966. { strings with the same length are equal }
  967. if (def1.deftype=stringdef) and (def2.deftype=stringdef) and
  968. (tstringdef(def1).string_typ=tstringdef(def2).string_typ) then
  969. begin
  970. b:=not(is_shortstring(def1)) or
  971. (tstringdef(def1).len=tstringdef(def2).len);
  972. end
  973. else
  974. if (def1.deftype=formaldef) and (def2.deftype=formaldef) then
  975. b:=true
  976. { file types with the same file element type are equal }
  977. { this is a problem for assign !! }
  978. { changed to allow if one is untyped }
  979. { all typed files are equal to the special }
  980. { typed file that has voiddef as elemnt type }
  981. { but must NOT match for text file !!! }
  982. else
  983. if (def1.deftype=filedef) and (def2.deftype=filedef) then
  984. b:=(tfiledef(def1).filetyp=tfiledef(def2).filetyp) and
  985. ((
  986. ((tfiledef(def1).typedfiletype.def=nil) and
  987. (tfiledef(def2).typedfiletype.def=nil)) or
  988. (
  989. (tfiledef(def1).typedfiletype.def<>nil) and
  990. (tfiledef(def2).typedfiletype.def<>nil) and
  991. is_equal(tfiledef(def1).typedfiletype.def,tfiledef(def2).typedfiletype.def)
  992. ) or
  993. ( (tfiledef(def1).typedfiletype.def=tdef(voidtype.def)) or
  994. (tfiledef(def2).typedfiletype.def=tdef(voidtype.def))
  995. )))
  996. { sets with the same element base type are equal }
  997. else
  998. if (def1.deftype=setdef) and (def2.deftype=setdef) then
  999. begin
  1000. if assigned(tsetdef(def1).elementtype.def) and
  1001. assigned(tsetdef(def2).elementtype.def) then
  1002. b:=is_subequal(tsetdef(def1).elementtype.def,tsetdef(def2).elementtype.def)
  1003. else
  1004. { empty set is compatible with everything }
  1005. b:=true;
  1006. end
  1007. else
  1008. if (def1.deftype=procvardef) and (def2.deftype=procvardef) then
  1009. begin
  1010. { poassembler isn't important for compatibility }
  1011. { if a method is assigned to a methodpointer }
  1012. { is checked before }
  1013. b:=(tprocvardef(def1).proctypeoption=tprocvardef(def2).proctypeoption) and
  1014. (tprocvardef(def1).proccalloption=tprocvardef(def2).proccalloption) and
  1015. ((tprocvardef(def1).procoptions * po_compatibility_options)=
  1016. (tprocvardef(def2).procoptions * po_compatibility_options)) and
  1017. is_equal(tprocvardef(def1).rettype.def,tprocvardef(def2).rettype.def) and
  1018. equal_paras(tprocvardef(def1).para,tprocvardef(def2).para,cp_all);
  1019. end
  1020. else
  1021. if (def1.deftype=arraydef) and (def2.deftype=arraydef) then
  1022. begin
  1023. if is_dynamic_array(def1) and is_dynamic_array(def2) then
  1024. b:=is_equal(tarraydef(def1).elementtype.def,tarraydef(def2).elementtype.def)
  1025. else
  1026. if is_array_of_const(def1) or is_array_of_const(def2) then
  1027. begin
  1028. b:=(is_array_of_const(def1) and is_array_of_const(def2)) or
  1029. (is_array_of_const(def1) and is_array_constructor(def2)) or
  1030. (is_array_of_const(def2) and is_array_constructor(def1));
  1031. end
  1032. else
  1033. if (is_dynamic_array(def1) or is_dynamic_array(def2)) then
  1034. begin
  1035. b := is_dynamic_array(def1) and is_dynamic_array(def2) and
  1036. is_equal(tarraydef(def1).elementtype.def,tarraydef(def2).elementtype.def);
  1037. end
  1038. else
  1039. if is_open_array(def1) or is_open_array(def2) then
  1040. begin
  1041. b:=is_equal(tarraydef(def1).elementtype.def,tarraydef(def2).elementtype.def);
  1042. end
  1043. else
  1044. begin
  1045. b:=not(m_tp7 in aktmodeswitches) and
  1046. not(m_delphi in aktmodeswitches) and
  1047. (tarraydef(def1).lowrange=tarraydef(def2).lowrange) and
  1048. (tarraydef(def1).highrange=tarraydef(def2).highrange) and
  1049. is_equal(tarraydef(def1).elementtype.def,tarraydef(def2).elementtype.def) and
  1050. is_equal(tarraydef(def1).rangetype.def,tarraydef(def2).rangetype.def);
  1051. end;
  1052. end
  1053. else
  1054. if (def1.deftype=classrefdef) and (def2.deftype=classrefdef) then
  1055. begin
  1056. { similar to pointerdef: }
  1057. if assigned(def1.typesym) and (tclassrefdef(def1).pointertype.def.deftype=forwarddef) then
  1058. b:=(def1.typesym=def2.typesym)
  1059. else
  1060. b:=is_equal(tclassrefdef(def1).pointertype.def,tclassrefdef(def2).pointertype.def);
  1061. end;
  1062. is_equal:=b;
  1063. end;
  1064. function is_subequal(def1, def2: tdef): boolean;
  1065. var
  1066. basedef1,basedef2 : tenumdef;
  1067. Begin
  1068. is_subequal := false;
  1069. if assigned(def1) and assigned(def2) then
  1070. Begin
  1071. if (def1.deftype = orddef) and (def2.deftype = orddef) then
  1072. Begin
  1073. { see p.47 of Turbo Pascal 7.01 manual for the separation of types }
  1074. { range checking for case statements is done with testrange }
  1075. case torddef(def1).typ of
  1076. u8bit,u16bit,u32bit,
  1077. s8bit,s16bit,s32bit,s64bit,u64bit :
  1078. is_subequal:=(torddef(def2).typ in [s64bit,u64bit,s32bit,u32bit,u8bit,s8bit,s16bit,u16bit]);
  1079. bool8bit,bool16bit,bool32bit :
  1080. is_subequal:=(torddef(def2).typ in [bool8bit,bool16bit,bool32bit]);
  1081. uchar :
  1082. is_subequal:=(torddef(def2).typ=uchar);
  1083. uwidechar :
  1084. is_subequal:=(torddef(def2).typ=uwidechar);
  1085. end;
  1086. end
  1087. else
  1088. Begin
  1089. { I assume that both enumerations are equal when the first }
  1090. { pointers are equal. }
  1091. { I changed this to assume that the enums are equal }
  1092. { if the basedefs are equal (FK) }
  1093. if (def1.deftype=enumdef) and (def2.deftype=enumdef) then
  1094. Begin
  1095. { get both basedefs }
  1096. basedef1:=tenumdef(def1);
  1097. while assigned(basedef1.basedef) do
  1098. basedef1:=basedef1.basedef;
  1099. basedef2:=tenumdef(def2);
  1100. while assigned(basedef2.basedef) do
  1101. basedef2:=basedef2.basedef;
  1102. is_subequal:=basedef1=basedef2;
  1103. {
  1104. if tenumdef(def1).firstenum = tenumdef(def2).firstenum then
  1105. is_subequal := TRUE;
  1106. }
  1107. end;
  1108. end;
  1109. end; { endif assigned ... }
  1110. end;
  1111. function assignment_overloaded(from_def,to_def : tdef) : tprocdef;
  1112. var
  1113. passprocs : pprocdeflist;
  1114. convtyp : tconverttype;
  1115. begin
  1116. assignment_overloaded:=nil;
  1117. if not assigned(overloaded_operators[_ASSIGNMENT]) then
  1118. exit;
  1119. { look for an exact match first }
  1120. passprocs:=overloaded_operators[_ASSIGNMENT].defs;
  1121. while assigned(passprocs) do
  1122. begin
  1123. if is_equal(passprocs^.def.rettype.def,to_def) and
  1124. (TParaItem(passprocs^.def.Para.first).paratype.def=from_def) then
  1125. begin
  1126. assignment_overloaded:=passprocs^.def;
  1127. exit;
  1128. end;
  1129. passprocs:=passprocs^.next;
  1130. end;
  1131. { .... then look for an equal match }
  1132. passprocs:=overloaded_operators[_ASSIGNMENT].defs;
  1133. while assigned(passprocs) do
  1134. begin
  1135. if is_equal(passprocs^.def.rettype.def,to_def) and
  1136. is_equal(TParaItem(passprocs^.def.Para.first).paratype.def,from_def) then
  1137. begin
  1138. assignment_overloaded:=passprocs^.def;
  1139. exit;
  1140. end;
  1141. passprocs:=passprocs^.next;
  1142. end;
  1143. { .... then for convert level 1 }
  1144. passprocs:=overloaded_operators[_ASSIGNMENT].defs;
  1145. while assigned(passprocs) do
  1146. begin
  1147. if is_equal(passprocs^.def.rettype.def,to_def) and
  1148. (isconvertable(from_def,TParaItem(passprocs^.def.Para.first).paratype.def,convtyp,ordconstn,false)=1) then
  1149. begin
  1150. assignment_overloaded:=passprocs^.def;
  1151. exit;
  1152. end;
  1153. passprocs:=passprocs^.next;
  1154. end;
  1155. end;
  1156. { Returns:
  1157. 0 - Not convertable
  1158. 1 - Convertable
  1159. 2 - Convertable, but not first choice }
  1160. function isconvertable(def_from,def_to : tdef;
  1161. var doconv : tconverttype;
  1162. fromtreetype : tnodetype;
  1163. explicit : boolean) : byte;
  1164. { Tbasetype:
  1165. uvoid,
  1166. u8bit,u16bit,u32bit,u64bit,
  1167. s8bit,s16bit,s32bit,s64bit,
  1168. bool8bit,bool16bit,bool32bit,
  1169. uchar,uwidechar }
  1170. type
  1171. tbasedef=(bvoid,bchar,bint,bbool);
  1172. const
  1173. basedeftbl:array[tbasetype] of tbasedef =
  1174. (bvoid,
  1175. bint,bint,bint,bint,
  1176. bint,bint,bint,bint,
  1177. bbool,bbool,bbool,
  1178. bchar,bchar);
  1179. basedefconverts : array[tbasedef,tbasedef] of tconverttype =
  1180. ((tc_not_possible,tc_not_possible,tc_not_possible,tc_not_possible),
  1181. (tc_not_possible,tc_char_2_char,tc_not_possible,tc_not_possible),
  1182. (tc_not_possible,tc_not_possible,tc_int_2_int,tc_int_2_bool),
  1183. (tc_not_possible,tc_not_possible,tc_bool_2_int,tc_bool_2_bool));
  1184. var
  1185. b : byte;
  1186. hd1,hd2 : tdef;
  1187. hct : tconverttype;
  1188. begin
  1189. { safety check }
  1190. if not(assigned(def_from) and assigned(def_to)) then
  1191. begin
  1192. isconvertable:=0;
  1193. exit;
  1194. end;
  1195. { tp7 procvar def support, in tp7 a procvar is always called, if the
  1196. procvar is passed explicit a addrn would be there }
  1197. if (m_tp_procvar in aktmodeswitches) and
  1198. (def_from.deftype=procvardef) and
  1199. (fromtreetype=loadn) and
  1200. { only if the procvar doesn't require any paramters }
  1201. (tprocvardef(def_from).minparacount = 0) then
  1202. begin
  1203. def_from:=tprocvardef(def_from).rettype.def;
  1204. end;
  1205. { we walk the wanted (def_to) types and check then the def_from
  1206. types if there is a conversion possible }
  1207. b:=0;
  1208. case def_to.deftype of
  1209. orddef :
  1210. begin
  1211. case def_from.deftype of
  1212. orddef :
  1213. begin
  1214. doconv:=basedefconverts[basedeftbl[torddef(def_from).typ],basedeftbl[torddef(def_to).typ]];
  1215. b:=1;
  1216. if (doconv=tc_not_possible) or
  1217. ((doconv=tc_int_2_bool) and
  1218. (not explicit) and
  1219. (not is_boolean(def_from))) or
  1220. ((doconv=tc_bool_2_int) and
  1221. (not explicit) and
  1222. (not is_boolean(def_to))) then
  1223. b:=0
  1224. else
  1225. { "punish" bad type conversions :) (JM) }
  1226. if not is_in_limit(def_from,def_to) and
  1227. (def_from.size > def_to.size) then
  1228. b := 2;
  1229. end;
  1230. enumdef :
  1231. begin
  1232. { needed for char(enum) }
  1233. if explicit then
  1234. begin
  1235. doconv:=tc_int_2_int;
  1236. b:=1;
  1237. end;
  1238. end;
  1239. end;
  1240. end;
  1241. stringdef :
  1242. begin
  1243. case def_from.deftype of
  1244. stringdef :
  1245. begin
  1246. doconv:=tc_string_2_string;
  1247. b:=1;
  1248. end;
  1249. orddef :
  1250. begin
  1251. { char to string}
  1252. if is_char(def_from) or
  1253. is_widechar(def_from) then
  1254. begin
  1255. doconv:=tc_char_2_string;
  1256. b:=1;
  1257. end;
  1258. end;
  1259. arraydef :
  1260. begin
  1261. { array of char to string, the length check is done by the firstpass of this node }
  1262. if is_chararray(def_from) or
  1263. (is_equal(tarraydef(def_from).elementtype.def,cchartype.def) and
  1264. is_open_array(def_from)) then
  1265. begin
  1266. doconv:=tc_chararray_2_string;
  1267. if is_open_array(def_from) or
  1268. (is_shortstring(def_to) and
  1269. (def_from.size <= 255)) or
  1270. (is_ansistring(def_to) and
  1271. (def_from.size > 255)) then
  1272. b:=1
  1273. else
  1274. b:=2;
  1275. end;
  1276. end;
  1277. pointerdef :
  1278. begin
  1279. { pchar can be assigned to short/ansistrings,
  1280. but not in tp7 compatible mode }
  1281. if is_pchar(def_from) and not(m_tp7 in aktmodeswitches) then
  1282. begin
  1283. doconv:=tc_pchar_2_string;
  1284. { trefer ansistrings because pchars can overflow shortstrings, }
  1285. { but only if ansistrings are the default (JM) }
  1286. if (is_shortstring(def_to) and
  1287. not(cs_ansistrings in aktlocalswitches)) or
  1288. (is_ansistring(def_to) and
  1289. (cs_ansistrings in aktlocalswitches)) then
  1290. b:=1
  1291. else
  1292. b:=2;
  1293. end;
  1294. end;
  1295. end;
  1296. end;
  1297. floatdef :
  1298. begin
  1299. case def_from.deftype of
  1300. orddef :
  1301. begin { ordinal to real }
  1302. if is_integer(def_from) then
  1303. begin
  1304. doconv:=tc_int_2_real;
  1305. b:=1;
  1306. end;
  1307. end;
  1308. floatdef :
  1309. begin { 2 float types ? }
  1310. if tfloatdef(def_from).typ=tfloatdef(def_to).typ then
  1311. doconv:=tc_equal
  1312. else
  1313. doconv:=tc_real_2_real;
  1314. b:=1;
  1315. end;
  1316. end;
  1317. end;
  1318. enumdef :
  1319. begin
  1320. if (def_from.deftype=enumdef) then
  1321. begin
  1322. if explicit then
  1323. begin
  1324. b:=1;
  1325. doconv:=tc_int_2_int;
  1326. end
  1327. else
  1328. begin
  1329. hd1:=def_from;
  1330. while assigned(tenumdef(hd1).basedef) do
  1331. hd1:=tenumdef(hd1).basedef;
  1332. hd2:=def_to;
  1333. while assigned(tenumdef(hd2).basedef) do
  1334. hd2:=tenumdef(hd2).basedef;
  1335. if (hd1=hd2) then
  1336. begin
  1337. b:=1;
  1338. { because of packenum they can have different sizes! (JM) }
  1339. doconv:=tc_int_2_int;
  1340. end;
  1341. end;
  1342. end;
  1343. end;
  1344. arraydef :
  1345. begin
  1346. { open array is also compatible with a single element of its base type }
  1347. if is_open_array(def_to) and
  1348. is_equal(tarraydef(def_to).elementtype.def,def_from) then
  1349. begin
  1350. doconv:=tc_equal;
  1351. b:=1;
  1352. end
  1353. else
  1354. begin
  1355. case def_from.deftype of
  1356. arraydef :
  1357. begin
  1358. { array constructor -> open array }
  1359. if is_open_array(def_to) and
  1360. is_array_constructor(def_from) then
  1361. begin
  1362. if is_void(tarraydef(def_from).elementtype.def) or
  1363. is_equal(tarraydef(def_to).elementtype.def,tarraydef(def_from).elementtype.def) then
  1364. begin
  1365. doconv:=tc_equal;
  1366. b:=1;
  1367. end
  1368. else
  1369. if isconvertable(tarraydef(def_from).elementtype.def,
  1370. tarraydef(def_to).elementtype.def,hct,arrayconstructorn,false)<>0 then
  1371. begin
  1372. doconv:=hct;
  1373. b:=2;
  1374. end;
  1375. end
  1376. else
  1377. { dynamic array -> open array }
  1378. if is_dynamic_array(def_from) and
  1379. is_open_array(def_to) and
  1380. is_equal(tarraydef(def_to).elementtype.def,tarraydef(def_from).elementtype.def) then
  1381. begin
  1382. doconv := tc_dynarray_2_openarray;
  1383. b := 2;
  1384. end
  1385. else
  1386. { array of tvarrec -> array of const }
  1387. if is_array_of_const(def_to) and
  1388. is_equal(tarraydef(def_to).elementtype.def,tarraydef(def_from).elementtype.def) then
  1389. begin
  1390. doconv:=tc_equal;
  1391. b:=1;
  1392. end;
  1393. end;
  1394. pointerdef :
  1395. begin
  1396. if is_zero_based_array(def_to) and
  1397. is_equal(tpointerdef(def_from).pointertype.def,tarraydef(def_to).elementtype.def) then
  1398. begin
  1399. doconv:=tc_pointer_2_array;
  1400. b:=1;
  1401. end;
  1402. end;
  1403. stringdef :
  1404. begin
  1405. { string to char array }
  1406. if (not is_special_array(def_to)) and
  1407. is_char(tarraydef(def_to).elementtype.def) then
  1408. begin
  1409. doconv:=tc_string_2_chararray;
  1410. b:=1;
  1411. end;
  1412. end;
  1413. orddef:
  1414. begin
  1415. if is_chararray(def_to) and
  1416. is_char(def_from) then
  1417. begin
  1418. doconv:=tc_char_2_chararray;
  1419. b:=2;
  1420. end;
  1421. end;
  1422. recorddef :
  1423. begin
  1424. { tvarrec -> array of constconst }
  1425. if is_array_of_const(def_to) and
  1426. is_equal(def_from,tarraydef(def_to).elementtype.def) then
  1427. begin
  1428. doconv:=tc_equal;
  1429. b:=1;
  1430. end;
  1431. end;
  1432. end;
  1433. end;
  1434. end;
  1435. pointerdef :
  1436. begin
  1437. case def_from.deftype of
  1438. stringdef :
  1439. begin
  1440. { string constant (which can be part of array constructor)
  1441. to zero terminated string constant }
  1442. if (fromtreetype in [arrayconstructorn,stringconstn]) and
  1443. is_pchar(def_to) or is_pwidechar(def_to) then
  1444. begin
  1445. doconv:=tc_cstring_2_pchar;
  1446. b:=1;
  1447. end;
  1448. end;
  1449. orddef :
  1450. begin
  1451. { char constant to zero terminated string constant }
  1452. if (fromtreetype=ordconstn) then
  1453. begin
  1454. if is_equal(def_from,cchartype.def) and
  1455. is_pchar(def_to) then
  1456. begin
  1457. doconv:=tc_cchar_2_pchar;
  1458. b:=1;
  1459. end
  1460. else
  1461. if is_integer(def_from) then
  1462. begin
  1463. doconv:=tc_cord_2_pointer;
  1464. b:=1;
  1465. end;
  1466. end;
  1467. end;
  1468. arraydef :
  1469. begin
  1470. { chararray to pointer }
  1471. if is_zero_based_array(def_from) and
  1472. is_equal(tarraydef(def_from).elementtype.def,tpointerdef(def_to).pointertype.def) then
  1473. begin
  1474. doconv:=tc_array_2_pointer;
  1475. b:=1;
  1476. end;
  1477. end;
  1478. pointerdef :
  1479. begin
  1480. { child class pointer can be assigned to anchestor pointers }
  1481. if (
  1482. (tpointerdef(def_from).pointertype.def.deftype=objectdef) and
  1483. (tpointerdef(def_to).pointertype.def.deftype=objectdef) and
  1484. tobjectdef(tpointerdef(def_from).pointertype.def).is_related(
  1485. tobjectdef(tpointerdef(def_to).pointertype.def))
  1486. ) or
  1487. { all pointers can be assigned to void-pointer }
  1488. is_equal(tpointerdef(def_to).pointertype.def,voidtype.def) or
  1489. { in my opnion, is this not clean pascal }
  1490. { well, but it's handy to use, it isn't ? (FK) }
  1491. is_equal(tpointerdef(def_from).pointertype.def,voidtype.def) then
  1492. begin
  1493. { but don't allow conversion between farpointer-pointer }
  1494. if (tpointerdef(def_to).is_far=tpointerdef(def_from).is_far) then
  1495. begin
  1496. doconv:=tc_equal;
  1497. b:=1;
  1498. end;
  1499. end;
  1500. end;
  1501. procvardef :
  1502. begin
  1503. { procedure variable can be assigned to an void pointer }
  1504. { Not anymore. Use the @ operator now.}
  1505. if not(m_tp_procvar in aktmodeswitches) and
  1506. (tpointerdef(def_to).pointertype.def.deftype=orddef) and
  1507. (torddef(tpointerdef(def_to).pointertype.def).typ=uvoid) then
  1508. begin
  1509. doconv:=tc_equal;
  1510. b:=1;
  1511. end;
  1512. end;
  1513. classrefdef,
  1514. objectdef :
  1515. begin
  1516. { class types and class reference type
  1517. can be assigned to void pointers }
  1518. if (
  1519. is_class_or_interface(def_from) or
  1520. (def_from.deftype=classrefdef)
  1521. ) and
  1522. (tpointerdef(def_to).pointertype.def.deftype=orddef) and
  1523. (torddef(tpointerdef(def_to).pointertype.def).typ=uvoid) then
  1524. begin
  1525. doconv:=tc_equal;
  1526. b:=1;
  1527. end;
  1528. end;
  1529. end;
  1530. end;
  1531. setdef :
  1532. begin
  1533. { automatic arrayconstructor -> set conversion }
  1534. if is_array_constructor(def_from) then
  1535. begin
  1536. doconv:=tc_arrayconstructor_2_set;
  1537. b:=1;
  1538. end;
  1539. end;
  1540. procvardef :
  1541. begin
  1542. { proc -> procvar }
  1543. if (def_from.deftype=procdef) and
  1544. (m_tp_procvar in aktmodeswitches) then
  1545. begin
  1546. doconv:=tc_proc_2_procvar;
  1547. if proc_to_procvar_equal(tprocdef(def_from),tprocvardef(def_to),false) then
  1548. b:=1;
  1549. end
  1550. { procvar -> procvar }
  1551. else
  1552. if (def_from.deftype=procvardef) and
  1553. (proc_to_procvar_equal(tprocvardef(def_from),tprocvardef(def_to),false)) then
  1554. begin
  1555. doconv:=tc_equal;
  1556. b := 2;
  1557. end
  1558. else
  1559. { for example delphi allows the assignement from pointers }
  1560. { to procedure variables }
  1561. if (m_pointer_2_procedure in aktmodeswitches) and
  1562. (def_from.deftype=pointerdef) and
  1563. (tpointerdef(def_from).pointertype.def.deftype=orddef) and
  1564. (torddef(tpointerdef(def_from).pointertype.def).typ=uvoid) then
  1565. begin
  1566. doconv:=tc_equal;
  1567. b:=1;
  1568. end
  1569. else
  1570. { nil is compatible with procvars }
  1571. if (fromtreetype=niln) then
  1572. begin
  1573. doconv:=tc_equal;
  1574. b:=1;
  1575. end;
  1576. end;
  1577. objectdef :
  1578. begin
  1579. { object pascal objects }
  1580. if (def_from.deftype=objectdef) and
  1581. tobjectdef(def_from).is_related(tobjectdef(def_to)) then
  1582. begin
  1583. doconv:=tc_equal;
  1584. b:=1;
  1585. end
  1586. else
  1587. { Class/interface specific }
  1588. if is_class_or_interface(def_to) then
  1589. begin
  1590. { void pointer also for delphi mode }
  1591. if (m_delphi in aktmodeswitches) and
  1592. is_voidpointer(def_from) then
  1593. begin
  1594. doconv:=tc_equal;
  1595. b:=1;
  1596. end
  1597. else
  1598. { nil is compatible with class instances and interfaces }
  1599. if (fromtreetype=niln) then
  1600. begin
  1601. doconv:=tc_equal;
  1602. b:=1;
  1603. end
  1604. { classes can be assigned to interfaces }
  1605. else if is_interface(def_to) and
  1606. is_class(def_from) and
  1607. assigned(tobjectdef(def_from).implementedinterfaces) and
  1608. (tobjectdef(def_from).implementedinterfaces.searchintf(def_to)<>-1) then
  1609. begin
  1610. doconv:=tc_class_2_intf;
  1611. b:=1;
  1612. end
  1613. { Interface 2 GUID handling }
  1614. else if (def_to=tdef(rec_tguid)) and
  1615. (fromtreetype=typen) and
  1616. is_interface(def_from) and
  1617. tobjectdef(def_from).isiidguidvalid then
  1618. begin
  1619. b:=1;
  1620. doconv:=tc_equal;
  1621. end;
  1622. end;
  1623. end;
  1624. classrefdef :
  1625. begin
  1626. { class reference types }
  1627. if (def_from.deftype=classrefdef) then
  1628. begin
  1629. doconv:=tc_equal;
  1630. if tobjectdef(tclassrefdef(def_from).pointertype.def).is_related(
  1631. tobjectdef(tclassrefdef(def_to).pointertype.def)) then
  1632. b:=1;
  1633. end
  1634. else
  1635. { nil is compatible with class references }
  1636. if (fromtreetype=niln) then
  1637. begin
  1638. doconv:=tc_equal;
  1639. b:=1;
  1640. end;
  1641. end;
  1642. filedef :
  1643. begin
  1644. { typed files are all equal to the abstract file type
  1645. name TYPEDFILE in system.pp in is_equal in types.pas
  1646. the problem is that it sholud be also compatible to FILE
  1647. but this would leed to a problem for ASSIGN RESET and REWRITE
  1648. when trying to find the good overloaded function !!
  1649. so all file function are doubled in system.pp
  1650. this is not very beautiful !!}
  1651. if (def_from.deftype=filedef) and
  1652. (
  1653. (
  1654. (tfiledef(def_from).filetyp = ft_typed) and
  1655. (tfiledef(def_to).filetyp = ft_typed) and
  1656. (
  1657. (tfiledef(def_from).typedfiletype.def = tdef(voidtype.def)) or
  1658. (tfiledef(def_to).typedfiletype.def = tdef(voidtype.def))
  1659. )
  1660. ) or
  1661. (
  1662. (
  1663. (tfiledef(def_from).filetyp = ft_untyped) and
  1664. (tfiledef(def_to).filetyp = ft_typed)
  1665. ) or
  1666. (
  1667. (tfiledef(def_from).filetyp = ft_typed) and
  1668. (tfiledef(def_to).filetyp = ft_untyped)
  1669. )
  1670. )
  1671. ) then
  1672. begin
  1673. doconv:=tc_equal;
  1674. b:=1;
  1675. end
  1676. end;
  1677. recorddef :
  1678. begin
  1679. { interface -> guid }
  1680. if is_interface(def_from) and
  1681. (def_to=rec_tguid) then
  1682. begin
  1683. doconv:=tc_intf_2_guid;
  1684. b:=1;
  1685. end
  1686. else
  1687. begin
  1688. { assignment overwritten ?? }
  1689. if assignment_overloaded(def_from,def_to)<>nil then
  1690. b:=2;
  1691. end;
  1692. end;
  1693. else
  1694. begin
  1695. { assignment overwritten ?? }
  1696. if assignment_overloaded(def_from,def_to)<>nil then
  1697. b:=2;
  1698. end;
  1699. end;
  1700. isconvertable:=b;
  1701. end;
  1702. function CheckTypes(def1,def2 : tdef) : boolean;
  1703. var
  1704. s1,s2 : string;
  1705. begin
  1706. if not is_equal(def1,def2) then
  1707. begin
  1708. { Crash prevention }
  1709. if (not assigned(def1)) or (not assigned(def2)) then
  1710. Message(type_e_mismatch)
  1711. else
  1712. begin
  1713. s1:=def1.typename;
  1714. s2:=def2.typename;
  1715. if (s1<>'<unknown type>') and (s2<>'<unknown type>') then
  1716. Message2(type_e_not_equal_types,def1.typename,def2.typename)
  1717. else
  1718. Message(type_e_mismatch);
  1719. end;
  1720. CheckTypes:=false;
  1721. end
  1722. else
  1723. CheckTypes:=true;
  1724. end;
  1725. end.
  1726. {
  1727. $Log$
  1728. Revision 1.1 2002-07-20 11:57:53 florian
  1729. * types.pas renamed to defbase.pas because D6 contains a types
  1730. unit so this would conflicts if D6 programms are compiled
  1731. + Willamette/SSE2 instructions to assembler added
  1732. Revision 1.75 2002/07/11 14:41:32 florian
  1733. * start of the new generic parameter handling
  1734. Revision 1.74 2002/07/01 16:23:54 peter
  1735. * cg64 patch
  1736. * basics for currency
  1737. * asnode updates for class and interface (not finished)
  1738. Revision 1.73 2002/05/18 13:34:21 peter
  1739. * readded missing revisions
  1740. Revision 1.72 2002/05/16 19:46:47 carl
  1741. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  1742. + try to fix temp allocation (still in ifdef)
  1743. + generic constructor calls
  1744. + start of tassembler / tmodulebase class cleanup
  1745. Revision 1.70 2002/05/12 16:53:16 peter
  1746. * moved entry and exitcode to ncgutil and cgobj
  1747. * foreach gets extra argument for passing local data to the
  1748. iterator function
  1749. * -CR checks also class typecasts at runtime by changing them
  1750. into as
  1751. * fixed compiler to cycle with the -CR option
  1752. * fixed stabs with elf writer, finally the global variables can
  1753. be watched
  1754. * removed a lot of routines from cga unit and replaced them by
  1755. calls to cgobj
  1756. * u32bit-s32bit updates for and,or,xor nodes. When one element is
  1757. u32bit then the other is typecasted also to u32bit without giving
  1758. a rangecheck warning/error.
  1759. * fixed pascal calling method with reversing also the high tree in
  1760. the parast, detected by tcalcst3 test
  1761. Revision 1.69 2002/04/25 20:16:39 peter
  1762. * moved more routines from cga/n386util
  1763. Revision 1.68 2002/04/15 19:08:22 carl
  1764. + target_info.size_of_pointer -> pointer_size
  1765. + some cleanup of unused types/variables
  1766. Revision 1.67 2002/04/07 13:40:29 carl
  1767. + update documentation
  1768. Revision 1.66 2002/04/02 17:11:32 peter
  1769. * tlocation,treference update
  1770. * LOC_CONSTANT added for better constant handling
  1771. * secondadd splitted in multiple routines
  1772. * location_force_reg added for loading a location to a register
  1773. of a specified size
  1774. * secondassignment parses now first the right and then the left node
  1775. (this is compatible with Kylix). This saves a lot of push/pop especially
  1776. with string operations
  1777. * adapted some routines to use the new cg methods
  1778. Revision 1.65 2002/04/01 20:57:14 jonas
  1779. * fixed web bug 1907
  1780. * fixed some other procvar related bugs (all related to accepting procvar
  1781. constructs with either too many or too little parameters)
  1782. (both merged, includes second typo fix of pexpr.pas)
  1783. Revision 1.64 2002/01/24 18:25:53 peter
  1784. * implicit result variable generation for assembler routines
  1785. * removed m_tp modeswitch, use m_tp7 or not(m_fpc) instead
  1786. Revision 1.63 2002/01/24 12:33:53 jonas
  1787. * adapted ranges of native types to int64 (e.g. high cardinal is no
  1788. longer longint($ffffffff), but just $fffffff in psystem)
  1789. * small additional fix in 64bit rangecheck code generation for 32 bit
  1790. processors
  1791. * adaption of ranges required the matching talgorithm used for selecting
  1792. which overloaded procedure to call to be adapted. It should now always
  1793. select the closest match for ordinal parameters.
  1794. + inttostr(qword) in sysstr.inc/sysstrh.inc
  1795. + abs(int64), sqr(int64), sqr(qword) in systemh.inc/generic.inc (previous
  1796. fixes were required to be able to add them)
  1797. * is_in_limit() moved from ncal to types unit, should always be used
  1798. instead of direct comparisons of low/high values of orddefs because
  1799. qword is a special case
  1800. Revision 1.62 2002/01/06 21:50:44 peter
  1801. * proc_to_procvar_equal fixed for procvar-procvar
  1802. Revision 1.61 2002/01/06 12:08:16 peter
  1803. * removed uauto from orddef, use new range_to_basetype generating
  1804. the correct ordinal type for a range
  1805. }