defbase.pas 77 KB

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