types.pas 34 KB

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