types.pas 74 KB

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