types.pas 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041
  1. {
  2. $Id$
  3. Copyright (C) 1993-98 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. interface
  20. uses
  21. cobjects,symtable;
  22. type
  23. tmmxtype = (mmxno,mmxu8bit,mmxs8bit,mmxu16bit,mmxs16bit,
  24. mmxu32bit,mmxs32bit,mmxfixed16,mmxsingle);
  25. const
  26. { true if we must never copy this parameter }
  27. never_copy_const_param : boolean = false;
  28. { returns true, if def defines an ordinal type }
  29. function is_ordinal(def : pdef) : boolean;
  30. { returns the min. value of the type }
  31. function get_min_value(def : pdef) : longint;
  32. { returns true, if def defines an ordinal type }
  33. function is_integer(def : pdef) : boolean;
  34. { true if p is a boolean }
  35. function is_boolean(def : pdef) : boolean;
  36. { true if p is a char }
  37. function is_char(def : pdef) : boolean;
  38. { true if p points to an open string def }
  39. function is_open_string(p : pdef) : boolean;
  40. { true if p points to an open array def }
  41. function is_open_array(p : pdef) : boolean;
  42. { true, if p points to an array of const def }
  43. function is_array_constructor(p : pdef) : boolean;
  44. { true if p is an ansi string def }
  45. function is_ansistring(p : pdef) : boolean;
  46. { true if p is a long string def }
  47. function is_longstring(p : pdef) : boolean;
  48. { true if p is a wide string def }
  49. function is_widestring(p : pdef) : boolean;
  50. { true if p is a short string def }
  51. function is_shortstring(p : pdef) : boolean;
  52. { true if p is a char array def }
  53. function is_chararray(p : pdef) : boolean;
  54. { true if p is a pchar def }
  55. function is_pchar(p : pdef) : boolean;
  56. { true if p is a smallset def }
  57. function is_smallset(p : pdef) : boolean;
  58. { returns true, if def defines a signed data type (only for ordinal types) }
  59. function is_signed(def : pdef) : boolean;
  60. { returns true, if def uses FPU }
  61. function is_fpu(def : pdef) : boolean;
  62. { true if the return value is in EAX }
  63. function ret_in_acc(def : pdef) : boolean;
  64. { true if uses a parameter as return value }
  65. function ret_in_param(def : pdef) : boolean;
  66. { true, if def is a 64 bit int type }
  67. function is_64bitint(def : pdef) : boolean;
  68. function push_high_param(def : pdef) : boolean;
  69. { true if a parameter is too large to copy and only the address is pushed }
  70. function push_addr_param(def : pdef) : boolean;
  71. { true, if def1 and def2 are semantical the same }
  72. function is_equal(def1,def2 : pdef) : boolean;
  73. { checks for type compatibility (subgroups of type) }
  74. { used for case statements... probably missing stuff }
  75. { to use on other types }
  76. function is_subequal(def1, def2: pdef): boolean;
  77. { same as is_equal, but with error message if failed }
  78. function CheckTypes(def1,def2 : pdef) : boolean;
  79. { true, if two parameter lists are equal }
  80. { if value_equal_const is true, call by value }
  81. { and call by const parameter are assumed as }
  82. { equal }
  83. function equal_paras(def1,def2 : pdefcoll;value_equal_const : boolean) : boolean;
  84. { true if a function can be assigned to a procvar }
  85. function proc_to_procvar_equal(def1,def2 : pabstractprocdef) : boolean;
  86. { if l isn't in the range of def a range check error is generated }
  87. procedure testrange(def : pdef;l : longint);
  88. { returns the range of def }
  89. procedure getrange(def : pdef;var l : longint;var h : longint);
  90. { some type helper routines for MMX support }
  91. function is_mmx_able_array(p : pdef) : boolean;
  92. { returns the mmx type }
  93. function mmx_type(p : pdef) : tmmxtype;
  94. { should we try to unget a temp of this type
  95. or is it done by temptoremove list (PM) }
  96. function ungettempoftype(p : pdef) : boolean;
  97. implementation
  98. uses
  99. strings,
  100. globtype,globals,verbose;
  101. function equal_paras(def1,def2 : pdefcoll;value_equal_const : boolean) : boolean;
  102. begin
  103. while (assigned(def1)) and (assigned(def2)) do
  104. begin
  105. if value_equal_const then
  106. begin
  107. if not(is_equal(def1^.data,def2^.data)) or
  108. ((def1^.paratyp<>def2^.paratyp) and
  109. ((def1^.paratyp=vs_var) or
  110. (def1^.paratyp=vs_var)
  111. )
  112. ) then
  113. begin
  114. equal_paras:=false;
  115. exit;
  116. end;
  117. end
  118. else
  119. begin
  120. if not(is_equal(def1^.data,def2^.data)) or
  121. (def1^.paratyp<>def2^.paratyp) then
  122. begin
  123. equal_paras:=false;
  124. exit;
  125. end;
  126. end;
  127. def1:=def1^.next;
  128. def2:=def2^.next;
  129. end;
  130. if (def1=nil) and (def2=nil) then
  131. equal_paras:=true
  132. else
  133. equal_paras:=false;
  134. end;
  135. { true if a function can be assigned to a procvar }
  136. function proc_to_procvar_equal(def1,def2 : pabstractprocdef) : boolean;
  137. begin
  138. if is_equal(def1^.retdef,def2^.retdef) and
  139. equal_paras(def1^.para1,def2^.para1,false) and
  140. ((def1^.options and po_compatibility_options)=
  141. (def2^.options and po_compatibility_options)) then
  142. proc_to_procvar_equal:=true
  143. else
  144. proc_to_procvar_equal:=false;
  145. end;
  146. { returns true, if def uses FPU }
  147. function is_fpu(def : pdef) : boolean;
  148. begin
  149. is_fpu:=(def^.deftype=floatdef) and (pfloatdef(def)^.typ<>f32bit);
  150. end;
  151. { true if p is an ordinal }
  152. function is_ordinal(def : pdef) : boolean;
  153. var
  154. dt : tbasetype;
  155. begin
  156. case def^.deftype of
  157. orddef : begin
  158. dt:=porddef(def)^.typ;
  159. is_ordinal:=dt in [uchar,u8bit,u16bit,u32bit,u64bit,s8bit,s16bit,s32bit,
  160. s64bitint,bool8bit,bool16bit,bool32bit];
  161. end;
  162. enumdef : is_ordinal:=true;
  163. else
  164. is_ordinal:=false;
  165. end;
  166. end;
  167. { returns the min. value of the type }
  168. function get_min_value(def : pdef) : longint;
  169. begin
  170. case def^.deftype of
  171. orddef:
  172. get_min_value:=porddef(def)^.low;
  173. enumdef:
  174. get_min_value:=penumdef(def)^.min;
  175. else
  176. get_min_value:=0;
  177. end;
  178. end;
  179. { true if p is an integer }
  180. function is_integer(def : pdef) : boolean;
  181. begin
  182. is_integer:=(def^.deftype=orddef) and
  183. (porddef(def)^.typ in [uauto,u8bit,u16bit,u32bit,s8bit,s16bit,s32bit]);
  184. end;
  185. { true if p is a boolean }
  186. function is_boolean(def : pdef) : boolean;
  187. begin
  188. is_boolean:=(def^.deftype=orddef) and
  189. (porddef(def)^.typ in [bool8bit,bool16bit,bool32bit]);
  190. end;
  191. { true if p is a char }
  192. function is_char(def : pdef) : boolean;
  193. begin
  194. is_char:=(def^.deftype=orddef) and
  195. (porddef(def)^.typ=uchar);
  196. end;
  197. { true if p is signed (integer) }
  198. function is_signed(def : pdef) : boolean;
  199. var
  200. dt : tbasetype;
  201. begin
  202. case def^.deftype of
  203. orddef : begin
  204. dt:=porddef(def)^.typ;
  205. is_signed:=(dt in [s8bit,s16bit,s32bit]);
  206. end;
  207. enumdef : is_signed:=false;
  208. else
  209. is_signed:=false;
  210. end;
  211. end;
  212. { true, if p points to an open array def }
  213. function is_open_string(p : pdef) : boolean;
  214. begin
  215. is_open_string:=(p^.deftype=stringdef) and
  216. (pstringdef(p)^.string_typ=st_shortstring) and
  217. (pstringdef(p)^.len=0);
  218. end;
  219. { true, if p points to an open array def }
  220. function is_open_array(p : pdef) : boolean;
  221. begin
  222. is_open_array:=(p^.deftype=arraydef) and
  223. (parraydef(p)^.lowrange=0) and
  224. (parraydef(p)^.highrange=-1) and
  225. not(is_array_constructor(p));
  226. end;
  227. { true, if p points to an array of const def }
  228. function is_array_constructor(p : pdef) : boolean;
  229. begin
  230. is_array_constructor:=(p^.deftype=arraydef) and
  231. (parraydef(p)^.IsConstructor);
  232. end;
  233. { true if p is an ansi string def }
  234. function is_ansistring(p : pdef) : boolean;
  235. begin
  236. is_ansistring:=(p^.deftype=stringdef) and
  237. (pstringdef(p)^.string_typ=st_ansistring);
  238. end;
  239. { true if p is an long string def }
  240. function is_longstring(p : pdef) : boolean;
  241. begin
  242. is_longstring:=(p^.deftype=stringdef) and
  243. (pstringdef(p)^.string_typ=st_longstring);
  244. end;
  245. { true if p is an wide string def }
  246. function is_widestring(p : pdef) : boolean;
  247. begin
  248. is_widestring:=(p^.deftype=stringdef) and
  249. (pstringdef(p)^.string_typ=st_widestring);
  250. end;
  251. { true if p is an short string def }
  252. function is_shortstring(p : pdef) : boolean;
  253. begin
  254. is_shortstring:=(p^.deftype=stringdef) and
  255. (pstringdef(p)^.string_typ=st_shortstring);
  256. end;
  257. { true if p is a char array def }
  258. function is_chararray(p : pdef) : boolean;
  259. begin
  260. is_chararray:=(p^.deftype=arraydef) and
  261. is_equal(parraydef(p)^.definition,cchardef);
  262. end;
  263. { true if p is a pchar def }
  264. function is_pchar(p : pdef) : boolean;
  265. begin
  266. is_pchar:=(p^.deftype=pointerdef) and
  267. is_equal(Ppointerdef(p)^.definition,cchardef);
  268. end;
  269. { true if p is a smallset def }
  270. function is_smallset(p : pdef) : boolean;
  271. begin
  272. is_smallset:=(p^.deftype=setdef) and
  273. (psetdef(p)^.settype=smallset);
  274. end;
  275. { true if the return value is in accumulator (EAX for i386), D0 for 68k }
  276. function ret_in_acc(def : pdef) : boolean;
  277. begin
  278. ret_in_acc:=(def^.deftype in [orddef,pointerdef,enumdef,classrefdef]) or
  279. ((def^.deftype=stringdef) and (pstringdef(def)^.string_typ in [st_ansistring,st_widestring])) or
  280. ((def^.deftype=procvardef) and ((pprocvardef(def)^.options and pomethodpointer)=0)) or
  281. ((def^.deftype=objectdef) and pobjectdef(def)^.isclass) or
  282. ((def^.deftype=setdef) and (psetdef(def)^.settype=smallset)) or
  283. ((def^.deftype=floatdef) and (pfloatdef(def)^.typ=f32bit));
  284. end;
  285. { true, if def is a 64 bit int type }
  286. function is_64bitint(def : pdef) : boolean;
  287. begin
  288. is_64bitint:=(def^.deftype=orddef) and (porddef(def)^.typ in [u64bit,s64bitint])
  289. end;
  290. { true if uses a parameter as return value }
  291. function ret_in_param(def : pdef) : boolean;
  292. begin
  293. ret_in_param:=(def^.deftype in [arraydef,recorddef]) or
  294. ((def^.deftype=stringdef) and (pstringdef(def)^.string_typ in [st_shortstring,st_longstring])) or
  295. ((def^.deftype=procvardef) and ((pprocvardef(def)^.options and pomethodpointer)<>0)) or
  296. ((def^.deftype=objectdef) and not(pobjectdef(def)^.isclass)) or
  297. ((def^.deftype=setdef) and (psetdef(def)^.settype<>smallset));
  298. end;
  299. function push_high_param(def : pdef) : boolean;
  300. begin
  301. push_high_param:=is_open_array(def) or is_open_string(def);
  302. end;
  303. { true if a parameter is too large to copy and only the address is pushed }
  304. function push_addr_param(def : pdef) : boolean;
  305. begin
  306. push_addr_param:=never_copy_const_param or
  307. (def^.deftype = formaldef) or
  308. { copy directly small records or arrays unless array of const ! PM }
  309. ((def^.deftype in [arraydef,recorddef]) and
  310. ((def^.size>4) or
  311. ((def^.deftype=arraydef) and
  312. (parraydef(def)^.IsConstructor or
  313. parraydef(def)^.isArrayOfConst or
  314. is_open_array(def)
  315. )
  316. )
  317. )
  318. ) or
  319. ((def^.deftype=objectdef) and not(pobjectdef(def)^.isclass)) or
  320. ((def^.deftype=stringdef) and (pstringdef(def)^.string_typ in [st_shortstring,st_longstring])) or
  321. ((def^.deftype=procvardef) and ((pprocvardef(def)^.options and pomethodpointer)<>0)) or
  322. ((def^.deftype=setdef) and (psetdef(def)^.settype<>smallset));
  323. end;
  324. { test if l is in the range of def, outputs error if out of range }
  325. procedure testrange(def : pdef;l : longint);
  326. var
  327. lv,hv: longint;
  328. begin
  329. getrange(def,lv,hv);
  330. if (def^.deftype=orddef) and
  331. (porddef(def)^.typ=u32bit) then
  332. begin
  333. if lv<=hv then
  334. begin
  335. if (l<lv) or (l>hv) then
  336. begin
  337. if (cs_check_range in aktlocalswitches) then
  338. Message(parser_e_range_check_error)
  339. else
  340. Message(parser_w_range_check_error);
  341. end;
  342. end
  343. else
  344. { this happens with the wrap around problem }
  345. { if lv is positive and hv is over $7ffffff }
  346. { so it seems negative }
  347. begin
  348. if ((l>=0) and (l<lv)) or
  349. ((l<0) and (l>hv)) then
  350. begin
  351. if (cs_check_range in aktlocalswitches) then
  352. Message(parser_e_range_check_error)
  353. else
  354. Message(parser_w_range_check_error);
  355. end;
  356. end;
  357. end
  358. else if (l<lv) or (l>hv) then
  359. begin
  360. if (cs_check_range in aktlocalswitches) then
  361. Message(parser_e_range_check_error)
  362. else
  363. Message(parser_w_range_check_error);
  364. end;
  365. end;
  366. { return the range from def in l and h }
  367. procedure getrange(def : pdef;var l : longint;var h : longint);
  368. begin
  369. case def^.deftype of
  370. orddef :
  371. begin
  372. l:=porddef(def)^.low;
  373. h:=porddef(def)^.high;
  374. end;
  375. enumdef :
  376. begin
  377. l:=penumdef(def)^.min;
  378. h:=penumdef(def)^.max;
  379. end;
  380. arraydef :
  381. begin
  382. l:=parraydef(def)^.lowrange;
  383. h:=parraydef(def)^.highrange;
  384. end;
  385. else
  386. internalerror(987);
  387. end;
  388. end;
  389. { should we try to unget a temp of this type
  390. or is it done by temptoremove list (PM) }
  391. function ungettempoftype(p : pdef) : boolean;
  392. begin
  393. ungettempoftype:=true;
  394. if assigned(p) and (p^.deftype=stringdef) and
  395. (pstringdef(p)^.string_typ in [st_ansistring,st_widestring]) then
  396. ungettempoftype:=false;
  397. end;
  398. function mmx_type(p : pdef) : tmmxtype;
  399. begin
  400. mmx_type:=mmxno;
  401. if is_mmx_able_array(p) then
  402. begin
  403. if parraydef(p)^.definition^.deftype=floatdef then
  404. case pfloatdef(parraydef(p)^.definition)^.typ of
  405. s32real:
  406. mmx_type:=mmxsingle;
  407. f16bit:
  408. mmx_type:=mmxfixed16
  409. end
  410. else
  411. case porddef(parraydef(p)^.definition)^.typ of
  412. u8bit:
  413. mmx_type:=mmxu8bit;
  414. s8bit:
  415. mmx_type:=mmxs8bit;
  416. u16bit:
  417. mmx_type:=mmxu16bit;
  418. s16bit:
  419. mmx_type:=mmxs16bit;
  420. u32bit:
  421. mmx_type:=mmxu32bit;
  422. s32bit:
  423. mmx_type:=mmxs32bit;
  424. end;
  425. end;
  426. end;
  427. function is_mmx_able_array(p : pdef) : boolean;
  428. begin
  429. {$ifdef SUPPORT_MMX}
  430. if (cs_mmx_saturation in aktlocalswitches) then
  431. begin
  432. is_mmx_able_array:=(p^.deftype=arraydef) and
  433. (
  434. (
  435. (parraydef(p)^.definition^.deftype=orddef) and
  436. (
  437. (
  438. (parraydef(p)^.lowrange=0) and
  439. (parraydef(p)^.highrange=1) and
  440. (porddef(parraydef(p)^.definition)^.typ in [u32bit,s32bit])
  441. )
  442. or
  443. (
  444. (parraydef(p)^.lowrange=0) and
  445. (parraydef(p)^.highrange=3) and
  446. (porddef(parraydef(p)^.definition)^.typ in [u16bit,s16bit])
  447. )
  448. )
  449. )
  450. or
  451. (
  452. (
  453. (parraydef(p)^.definition^.deftype=floatdef) and
  454. (
  455. (parraydef(p)^.lowrange=0) and
  456. (parraydef(p)^.highrange=3) and
  457. (pfloatdef(parraydef(p)^.definition)^.typ=f16bit)
  458. ) or
  459. (
  460. (parraydef(p)^.lowrange=0) and
  461. (parraydef(p)^.highrange=1) and
  462. (pfloatdef(parraydef(p)^.definition)^.typ=s32real)
  463. )
  464. )
  465. )
  466. );
  467. end
  468. else
  469. begin
  470. is_mmx_able_array:=(p^.deftype=arraydef) and
  471. (
  472. (
  473. (parraydef(p)^.definition^.deftype=orddef) and
  474. (
  475. (
  476. (parraydef(p)^.lowrange=0) and
  477. (parraydef(p)^.highrange=1) and
  478. (porddef(parraydef(p)^.definition)^.typ in [u32bit,s32bit])
  479. )
  480. or
  481. (
  482. (parraydef(p)^.lowrange=0) and
  483. (parraydef(p)^.highrange=3) and
  484. (porddef(parraydef(p)^.definition)^.typ in [u16bit,s16bit])
  485. )
  486. or
  487. (
  488. (parraydef(p)^.lowrange=0) and
  489. (parraydef(p)^.highrange=7) and
  490. (porddef(parraydef(p)^.definition)^.typ in [u8bit,s8bit])
  491. )
  492. )
  493. )
  494. or
  495. (
  496. (parraydef(p)^.definition^.deftype=floatdef) and
  497. (
  498. (
  499. (parraydef(p)^.lowrange=0) and
  500. (parraydef(p)^.highrange=3) and
  501. (pfloatdef(parraydef(p)^.definition)^.typ=f32bit)
  502. )
  503. or
  504. (
  505. (parraydef(p)^.lowrange=0) and
  506. (parraydef(p)^.highrange=1) and
  507. (pfloatdef(parraydef(p)^.definition)^.typ=s32real)
  508. )
  509. )
  510. )
  511. );
  512. end;
  513. {$else SUPPORT_MMX}
  514. is_mmx_able_array:=false;
  515. {$endif SUPPORT_MMX}
  516. end;
  517. function is_equal(def1,def2 : pdef) : boolean;
  518. const
  519. procvarmask = not(poassembler or pomethodpointer or povirtualmethod or
  520. pooverridingmethod or pomsgint or pomsgstr);
  521. var
  522. b : boolean;
  523. hd : pdef;
  524. hp1,hp2 : pdefcoll;
  525. begin
  526. { both types must exists }
  527. if not (assigned(def1) and assigned(def2)) then
  528. begin
  529. is_equal:=false;
  530. exit;
  531. end;
  532. { be sure, that if there is a stringdef, that this is def1 }
  533. if def2^.deftype=stringdef then
  534. begin
  535. hd:=def1;
  536. def1:=def2;
  537. def2:=hd;
  538. end;
  539. b:=false;
  540. { both point to the same definition ? }
  541. if def1=def2 then
  542. b:=true
  543. else
  544. { pointer with an equal definition are equal }
  545. if (def1^.deftype=pointerdef) and (def2^.deftype=pointerdef) then
  546. begin
  547. { here a problem detected in tabsolutesym }
  548. { the types can be forward type !! }
  549. if assigned(def1^.sym) and ((def1^.sym^.properties and sp_forwarddef)<>0) then
  550. b:=(def1^.sym=def2^.sym)
  551. else
  552. b:=ppointerdef(def1)^.definition=ppointerdef(def2)^.definition;
  553. end
  554. else
  555. { ordinals are equal only when the ordinal type is equal }
  556. if (def1^.deftype=orddef) and (def2^.deftype=orddef) then
  557. begin
  558. case porddef(def1)^.typ of
  559. u8bit,u16bit,u32bit,
  560. s8bit,s16bit,s32bit:
  561. b:=((porddef(def1)^.typ=porddef(def2)^.typ) and
  562. (porddef(def1)^.low=porddef(def2)^.low) and
  563. (porddef(def1)^.high=porddef(def2)^.high));
  564. uvoid,uchar,
  565. bool8bit,bool16bit,bool32bit:
  566. b:=(porddef(def1)^.typ=porddef(def2)^.typ);
  567. end;
  568. end
  569. else
  570. if (def1^.deftype=floatdef) and (def2^.deftype=floatdef) then
  571. b:=pfloatdef(def1)^.typ=pfloatdef(def2)^.typ
  572. else
  573. { strings with the same length are equal }
  574. if (def1^.deftype=stringdef) and (def2^.deftype=stringdef) and
  575. (pstringdef(def1)^.string_typ=pstringdef(def2)^.string_typ) then
  576. begin
  577. b:=not(is_shortstring(def1)) or
  578. (pstringdef(def1)^.len=pstringdef(def2)^.len);
  579. end
  580. else
  581. if (def1^.deftype=formaldef) and (def2^.deftype=formaldef) then
  582. b:=true
  583. { file types with the same file element type are equal }
  584. { this is a problem for assign !! }
  585. { changed to allow if one is untyped }
  586. { all typed files are equal to the special }
  587. { typed file that has voiddef as elemnt type }
  588. { but must NOT match for text file !!! }
  589. else
  590. if (def1^.deftype=filedef) and (def2^.deftype=filedef) then
  591. b:=(pfiledef(def1)^.filetype=pfiledef(def2)^.filetype) and
  592. ((
  593. ((pfiledef(def1)^.typed_as=nil) and
  594. (pfiledef(def2)^.typed_as=nil)) or
  595. (
  596. (pfiledef(def1)^.typed_as<>nil) and
  597. (pfiledef(def2)^.typed_as<>nil) and
  598. is_equal(pfiledef(def1)^.typed_as,pfiledef(def2)^.typed_as)
  599. ) or
  600. ( (pfiledef(def1)^.typed_as=pdef(voiddef)) or
  601. (pfiledef(def2)^.typed_as=pdef(voiddef))
  602. )))
  603. { sets with the same element type are equal }
  604. else
  605. if (def1^.deftype=setdef) and (def2^.deftype=setdef) then
  606. begin
  607. if assigned(psetdef(def1)^.setof) and
  608. assigned(psetdef(def2)^.setof) then
  609. b:=(psetdef(def1)^.setof^.deftype=psetdef(def2)^.setof^.deftype)
  610. else
  611. b:=true;
  612. end
  613. else
  614. if (def1^.deftype=procvardef) and (def2^.deftype=procvardef) then
  615. begin
  616. { poassembler isn't important for compatibility }
  617. { if a method is assigned to a methodpointer }
  618. { is checked before }
  619. b:=((pprocvardef(def1)^.options and procvarmask)=(pprocvardef(def2)^.options and procvarmask)) and
  620. is_equal(pprocvardef(def1)^.retdef,pprocvardef(def2)^.retdef);
  621. { now evalute the parameters }
  622. if b then
  623. begin
  624. hp1:=pprocvardef(def1)^.para1;
  625. hp2:=pprocvardef(def1)^.para1;
  626. while assigned(hp1) and assigned(hp2) do
  627. begin
  628. if not(is_equal(hp1^.data,hp2^.data)) or
  629. not(hp1^.paratyp=hp2^.paratyp) then
  630. begin
  631. b:=false;
  632. break;
  633. end;
  634. hp1:=hp1^.next;
  635. hp2:=hp2^.next;
  636. end;
  637. b:=(hp1=nil) and (hp2=nil);
  638. end;
  639. end
  640. else
  641. if (def1^.deftype=arraydef) and (def2^.deftype=arraydef) and
  642. (is_open_array(def1) or is_open_array(def2)) then
  643. begin
  644. if parraydef(def1)^.IsArrayOfConst or parraydef(def2)^.IsArrayOfConst then
  645. b:=true
  646. else
  647. b:=is_equal(parraydef(def1)^.definition,parraydef(def2)^.definition);
  648. end
  649. else
  650. if (def1^.deftype=classrefdef) and (def2^.deftype=classrefdef) then
  651. begin
  652. { similar to pointerdef: }
  653. if assigned(def1^.sym) and ((def1^.sym^.properties and sp_forwarddef)<>0) then
  654. b:=(def1^.sym=def2^.sym)
  655. else
  656. b:=is_equal(pclassrefdef(def1)^.definition,pclassrefdef(def2)^.definition);
  657. end;
  658. is_equal:=b;
  659. end;
  660. function is_subequal(def1, def2: pdef): boolean;
  661. Begin
  662. if assigned(def1) and assigned(def2) then
  663. Begin
  664. is_subequal := FALSE;
  665. if (def1^.deftype = orddef) and (def2^.deftype = orddef) then
  666. Begin
  667. { see p.47 of Turbo Pascal 7.01 manual for the separation of types }
  668. { range checking for case statements is done with testrange }
  669. case porddef(def1)^.typ of
  670. u8bit,u16bit,u32bit,
  671. s8bit,s16bit,s32bit :
  672. is_subequal:=(porddef(def2)^.typ in [s32bit,u32bit,u8bit,s8bit,s16bit,u16bit]);
  673. bool8bit,bool16bit,bool32bit :
  674. is_subequal:=(porddef(def2)^.typ in [bool8bit,bool16bit,bool32bit]);
  675. uchar :
  676. is_subequal:=(porddef(def2)^.typ=uchar);
  677. end;
  678. end
  679. else
  680. Begin
  681. { I assume that both enumerations are equal when the first }
  682. { pointers are equal. }
  683. if (def1^.deftype = enumdef) and (def2^.deftype =enumdef) then
  684. Begin
  685. if penumdef(def1)^.firstenum = penumdef(def2)^.firstenum then
  686. is_subequal := TRUE;
  687. end;
  688. end;
  689. end; { endif assigned ... }
  690. end;
  691. function CheckTypes(def1,def2 : pdef) : boolean;
  692. begin
  693. if not is_equal(def1,def2) then
  694. begin
  695. { Crash prevention }
  696. if (not assigned(def1)) or (not assigned(def2)) then
  697. Message(type_e_mismatch)
  698. else
  699. Message2(type_e_not_equal_types,def1^.typename,def2^.typename);
  700. CheckTypes:=false;
  701. end
  702. else
  703. CheckTypes:=true;
  704. end;
  705. end.
  706. {
  707. $Log$
  708. Revision 1.61 1999-05-19 10:31:56 florian
  709. * two bugs reported by Romio (bugs 13) are fixed:
  710. - empty array constructors are now handled correctly (e.g. for sysutils.format)
  711. - comparsion of ansistrings was sometimes coded wrong
  712. Revision 1.60 1999/05/18 14:16:01 peter
  713. * containsself fixes
  714. * checktypes()
  715. Revision 1.59 1999/05/18 09:52:24 peter
  716. * procedure of object and addrn fixes
  717. Revision 1.58 1999/04/19 09:29:51 pierre
  718. + ungettempoftype(pdef) boolean function
  719. returns true (can call ungetiftemp )
  720. unless the temp should be "unget" with temptoremove
  721. (currently ansistring or widestring !)
  722. Revision 1.57 1999/04/14 09:15:08 peter
  723. * first things to store the symbol/def number in the ppu
  724. Revision 1.56 1999/03/24 23:17:42 peter
  725. * fixed bugs 212,222,225,227,229,231,233
  726. Revision 1.55 1999/03/09 11:45:42 pierre
  727. * small arrays and records (size <=4) are copied directly
  728. Revision 1.54 1999/03/02 22:52:20 peter
  729. * fixed char array, which can start with all possible values
  730. Revision 1.53 1999/02/25 21:02:57 peter
  731. * ag386bin updates
  732. + coff writer
  733. Revision 1.52 1999/02/24 09:51:44 florian
  734. * wrong warning fixed, if a non-virtual method was hidden by a virtual
  735. method (repoerted by Matthias Koeppe)
  736. Revision 1.51 1999/02/22 23:33:31 florian
  737. + message directive for integers added
  738. Revision 1.50 1999/02/22 20:13:42 florian
  739. + first implementation of message keyword
  740. Revision 1.49 1999/02/16 00:45:30 peter
  741. * fixed crashes by forgotten strpnew() for init_symbol
  742. Revision 1.48 1999/02/09 23:03:08 florian
  743. * check for duplicate field names in inherited classes/objects
  744. * bug with self from the mailing list solved (the problem
  745. was that classes were sometimes pushed wrong)
  746. Revision 1.47 1999/01/27 00:14:01 florian
  747. * "procedure of object"-stuff fixed
  748. Revision 1.46 1999/01/21 22:10:54 peter
  749. * fixed array of const
  750. * generic platform independent high() support
  751. Revision 1.45 1999/01/20 12:34:22 peter
  752. * fixed typed file read/write
  753. Revision 1.44 1999/01/15 11:33:03 pierre
  754. * bug in mmx code removed
  755. Revision 1.43 1998/12/30 13:41:20 peter
  756. * released valuepara
  757. Revision 1.42 1998/12/11 00:04:03 peter
  758. + globtype,tokens,version unit splitted from globals
  759. Revision 1.41 1998/12/10 09:47:33 florian
  760. + basic operations with int64/qord (compiler with -dint64)
  761. + rtti of enumerations extended: names are now written
  762. Revision 1.40 1998/12/04 10:18:14 florian
  763. * some stuff for procedures of object added
  764. * bug with overridden virtual constructors fixed (reported by Italo Gomes)
  765. Revision 1.39 1998/11/27 14:50:55 peter
  766. + open strings, $P switch support
  767. Revision 1.38 1998/11/18 15:44:24 peter
  768. * VALUEPARA for tp7 compatible value parameters
  769. Revision 1.37 1998/11/13 10:15:50 peter
  770. * fixed ptr() with constants
  771. Revision 1.36 1998/11/10 10:09:21 peter
  772. * va_list -> array of const
  773. Revision 1.35 1998/10/19 08:55:13 pierre
  774. * wrong stabs info corrected once again !!
  775. + variable vmt offset with vmt field only if required
  776. implemented now !!!
  777. Revision 1.34 1998/10/12 09:50:06 florian
  778. + support of <procedure var type>:=<pointer> in delphi mode added
  779. Revision 1.33 1998/10/06 20:43:30 peter
  780. * fixed set of bugs. like set of false..true set of #1..#255 and
  781. set of #1..true which was allowed
  782. Revision 1.32 1998/10/05 21:33:35 peter
  783. * fixed 161,165,166,167,168
  784. Revision 1.31 1998/09/23 09:58:56 peter
  785. * first working array of const things
  786. Revision 1.30 1998/09/22 15:40:58 peter
  787. * some extra ifdef GDB
  788. Revision 1.29 1998/09/16 12:37:31 michael
  789. Added FPC_ prefix to abstracterror
  790. Revision 1.28 1998/09/09 16:44:23 florian
  791. * I hope, the case bug is fixed now
  792. Revision 1.27 1998/09/07 17:37:07 florian
  793. * first fixes for published properties
  794. Revision 1.26 1998/09/04 12:24:31 florian
  795. * bug0159 fixed
  796. Revision 1.25 1998/09/04 09:06:36 florian
  797. * bug0132 fixed
  798. Revision 1.24 1998/09/04 08:36:49 peter
  799. * fixed boolean:=integer which is not explicit
  800. Revision 1.23 1998/09/01 17:39:55 peter
  801. + internal constant functions
  802. Revision 1.22 1998/09/01 12:53:28 peter
  803. + aktpackenum
  804. Revision 1.21 1998/08/19 00:42:45 peter
  805. + subrange types for enums
  806. + checking for bounds type with ranges
  807. Revision 1.20 1998/08/18 14:17:14 pierre
  808. * bug about assigning the return value of a function to
  809. a procvar fixed : warning
  810. assigning a proc to a procvar need @ in FPC mode !!
  811. * missing file/line info restored
  812. Revision 1.19 1998/08/18 09:24:48 pierre
  813. * small warning position bug fixed
  814. * support_mmx switches splitting was missing
  815. * rhide error and warning output corrected
  816. Revision 1.18 1998/08/14 18:18:49 peter
  817. + dynamic set contruction
  818. * smallsets are now working (always longint size)
  819. Revision 1.17 1998/08/05 16:00:17 florian
  820. * some fixes for ansi strings
  821. Revision 1.16 1998/07/20 23:35:50 michael
  822. Const ansistrings are not copied.
  823. Revision 1.15 1998/07/18 22:54:32 florian
  824. * some ansi/wide/longstring support fixed:
  825. o parameter passing
  826. o returning as result from functions
  827. Revision 1.14 1998/06/12 14:50:50 peter
  828. * removed the tree dependency to types.pas
  829. * long_fil.pas support (not fully tested yet)
  830. Revision 1.13 1998/06/03 22:49:07 peter
  831. + wordbool,longbool
  832. * rename bis,von -> high,low
  833. * moved some systemunit loading/creating to psystem.pas
  834. Revision 1.12 1998/05/12 10:47:00 peter
  835. * moved printstatus to verb_def
  836. + V_Normal which is between V_Error and V_Warning and doesn't have a
  837. prefix like error: warning: and is included in V_Default
  838. * fixed some messages
  839. * first time parameter scan is only for -v and -T
  840. - removed old style messages
  841. Revision 1.11 1998/05/01 16:38:46 florian
  842. * handling of private and protected fixed
  843. + change_keywords_to_tp implemented to remove
  844. keywords which aren't supported by tp
  845. * break and continue are now symbols of the system unit
  846. + widestring, longstring and ansistring type released
  847. Revision 1.10 1998/04/29 10:34:08 pierre
  848. + added some code for ansistring (not complete nor working yet)
  849. * corrected operator overloading
  850. * corrected nasm output
  851. + started inline procedures
  852. + added starstarn : use ** for exponentiation (^ gave problems)
  853. + started UseTokenInfo cond to get accurate positions
  854. Revision 1.9 1998/04/21 10:16:49 peter
  855. * patches from strasbourg
  856. * objects is not used anymore in the fpc compiled version
  857. Revision 1.8 1998/04/12 22:39:44 florian
  858. * problem with read access to properties solved
  859. * correct handling of hidding methods via virtual (COM)
  860. * correct result type of constructor calls (COM), the resulttype
  861. depends now on the type of the class reference
  862. Revision 1.7 1998/04/10 21:36:56 florian
  863. + some stuff to support method pointers (procedure of object) added
  864. (declaration, parameter handling)
  865. Revision 1.6 1998/04/10 15:39:49 florian
  866. * more fixes to get classes.pas compiled
  867. Revision 1.5 1998/04/09 23:02:16 florian
  868. * small problems solved to get remake3 work
  869. Revision 1.4 1998/04/08 16:58:09 pierre
  870. * several bugfixes
  871. ADD ADC and AND are also sign extended
  872. nasm output OK (program still crashes at end
  873. and creates wrong assembler files !!)
  874. procsym types sym in tdef removed !!
  875. Revision 1.3 1998/04/08 11:34:22 peter
  876. * nasm works (linux only tested)
  877. }