types.pas 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012
  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. var
  516. b : boolean;
  517. hd : pdef;
  518. hp1,hp2 : pdefcoll;
  519. begin
  520. { both types must exists }
  521. if not (assigned(def1) and assigned(def2)) then
  522. begin
  523. is_equal:=false;
  524. exit;
  525. end;
  526. { be sure, that if there is a stringdef, that this is def1 }
  527. if def2^.deftype=stringdef then
  528. begin
  529. hd:=def1;
  530. def1:=def2;
  531. def2:=hd;
  532. end;
  533. b:=false;
  534. { both point to the same definition ? }
  535. if def1=def2 then
  536. b:=true
  537. else
  538. { pointer with an equal definition are equal }
  539. if (def1^.deftype=pointerdef) and (def2^.deftype=pointerdef) then
  540. begin
  541. { here a problem detected in tabsolutesym }
  542. { the types can be forward type !! }
  543. if assigned(def1^.sym) and ((def1^.sym^.properties and sp_forwarddef)<>0) then
  544. b:=(def1^.sym=def2^.sym)
  545. else
  546. b:=ppointerdef(def1)^.definition=ppointerdef(def2)^.definition;
  547. end
  548. else
  549. { ordinals are equal only when the ordinal type is equal }
  550. if (def1^.deftype=orddef) and (def2^.deftype=orddef) then
  551. begin
  552. case porddef(def1)^.typ of
  553. u8bit,u16bit,u32bit,
  554. s8bit,s16bit,s32bit:
  555. b:=((porddef(def1)^.typ=porddef(def2)^.typ) and
  556. (porddef(def1)^.low=porddef(def2)^.low) and
  557. (porddef(def1)^.high=porddef(def2)^.high));
  558. uvoid,uchar,
  559. bool8bit,bool16bit,bool32bit:
  560. b:=(porddef(def1)^.typ=porddef(def2)^.typ);
  561. end;
  562. end
  563. else
  564. if (def1^.deftype=floatdef) and (def2^.deftype=floatdef) then
  565. b:=pfloatdef(def1)^.typ=pfloatdef(def2)^.typ
  566. else
  567. { strings with the same length are equal }
  568. if (def1^.deftype=stringdef) and (def2^.deftype=stringdef) and
  569. (pstringdef(def1)^.string_typ=pstringdef(def2)^.string_typ) then
  570. begin
  571. b:=not(is_shortstring(def1)) or
  572. (pstringdef(def1)^.len=pstringdef(def2)^.len);
  573. end
  574. else
  575. if (def1^.deftype=formaldef) and (def2^.deftype=formaldef) then
  576. b:=true
  577. { file types with the same file element type are equal }
  578. { this is a problem for assign !! }
  579. { changed to allow if one is untyped }
  580. { all typed files are equal to the special }
  581. { typed file that has voiddef as elemnt type }
  582. { but must NOT match for text file !!! }
  583. else
  584. if (def1^.deftype=filedef) and (def2^.deftype=filedef) then
  585. b:=(pfiledef(def1)^.filetype=pfiledef(def2)^.filetype) and
  586. ((
  587. ((pfiledef(def1)^.typed_as=nil) and
  588. (pfiledef(def2)^.typed_as=nil)) or
  589. (
  590. (pfiledef(def1)^.typed_as<>nil) and
  591. (pfiledef(def2)^.typed_as<>nil) and
  592. is_equal(pfiledef(def1)^.typed_as,pfiledef(def2)^.typed_as)
  593. ) or
  594. ( (pfiledef(def1)^.typed_as=pdef(voiddef)) or
  595. (pfiledef(def2)^.typed_as=pdef(voiddef))
  596. )))
  597. { sets with the same element type are equal }
  598. else
  599. if (def1^.deftype=setdef) and (def2^.deftype=setdef) then
  600. begin
  601. if assigned(psetdef(def1)^.setof) and
  602. assigned(psetdef(def2)^.setof) then
  603. b:=(psetdef(def1)^.setof^.deftype=psetdef(def2)^.setof^.deftype)
  604. else
  605. b:=true;
  606. end
  607. else
  608. if (def1^.deftype=procvardef) and (def2^.deftype=procvardef) then
  609. begin
  610. { poassembler isn't important for compatibility }
  611. { if a method is assigned to a methodpointer }
  612. { is checked before }
  613. b:=((pprocvardef(def1)^.options and not(poassembler or pomethodpointer or
  614. povirtualmethod or pooverridingmethod))=
  615. (pprocvardef(def2)^.options and not(poassembler or pomethodpointer or
  616. povirtualmethod or pooverridingmethod))
  617. ) and
  618. is_equal(pprocvardef(def1)^.retdef,pprocvardef(def2)^.retdef);
  619. { now evalute the parameters }
  620. if b then
  621. begin
  622. hp1:=pprocvardef(def1)^.para1;
  623. hp2:=pprocvardef(def1)^.para1;
  624. while assigned(hp1) and assigned(hp2) do
  625. begin
  626. if not(is_equal(hp1^.data,hp2^.data)) or
  627. not(hp1^.paratyp=hp2^.paratyp) then
  628. begin
  629. b:=false;
  630. break;
  631. end;
  632. hp1:=hp1^.next;
  633. hp2:=hp2^.next;
  634. end;
  635. b:=(hp1=nil) and (hp2=nil);
  636. end;
  637. end
  638. else
  639. if (def1^.deftype=arraydef) and (def2^.deftype=arraydef) and
  640. (is_open_array(def1) or is_open_array(def2)) then
  641. begin
  642. if parraydef(def1)^.IsArrayOfConst or parraydef(def2)^.IsArrayOfConst then
  643. b:=true
  644. else
  645. b:=is_equal(parraydef(def1)^.definition,parraydef(def2)^.definition);
  646. end
  647. else
  648. if (def1^.deftype=classrefdef) and (def2^.deftype=classrefdef) then
  649. begin
  650. { similar to pointerdef: }
  651. if assigned(def1^.sym) and ((def1^.sym^.properties and sp_forwarddef)<>0) then
  652. b:=(def1^.sym=def2^.sym)
  653. else
  654. b:=is_equal(pclassrefdef(def1)^.definition,pclassrefdef(def2)^.definition);
  655. end;
  656. is_equal:=b;
  657. end;
  658. function is_subequal(def1, def2: pdef): boolean;
  659. Begin
  660. if assigned(def1) and assigned(def2) then
  661. Begin
  662. is_subequal := FALSE;
  663. if (def1^.deftype = orddef) and (def2^.deftype = orddef) then
  664. Begin
  665. { see p.47 of Turbo Pascal 7.01 manual for the separation of types }
  666. { range checking for case statements is done with testrange }
  667. case porddef(def1)^.typ of
  668. u8bit,u16bit,u32bit,
  669. s8bit,s16bit,s32bit :
  670. is_subequal:=(porddef(def2)^.typ in [s32bit,u32bit,u8bit,s8bit,s16bit,u16bit]);
  671. bool8bit,bool16bit,bool32bit :
  672. is_subequal:=(porddef(def2)^.typ in [bool8bit,bool16bit,bool32bit]);
  673. uchar :
  674. is_subequal:=(porddef(def2)^.typ=uchar);
  675. end;
  676. end
  677. else
  678. Begin
  679. { I assume that both enumerations are equal when the first }
  680. { pointers are equal. }
  681. if (def1^.deftype = enumdef) and (def2^.deftype =enumdef) then
  682. Begin
  683. if penumdef(def1)^.firstenum = penumdef(def2)^.firstenum then
  684. is_subequal := TRUE;
  685. end;
  686. end;
  687. end; { endif assigned ... }
  688. end;
  689. end.
  690. {
  691. $Log$
  692. Revision 1.58 1999-04-19 09:29:51 pierre
  693. + ungettempoftype(pdef) boolean function
  694. returns true (can call ungetiftemp )
  695. unless the temp should be "unget" with temptoremove
  696. (currently ansistring or widestring !)
  697. Revision 1.57 1999/04/14 09:15:08 peter
  698. * first things to store the symbol/def number in the ppu
  699. Revision 1.56 1999/03/24 23:17:42 peter
  700. * fixed bugs 212,222,225,227,229,231,233
  701. Revision 1.55 1999/03/09 11:45:42 pierre
  702. * small arrays and records (size <=4) are copied directly
  703. Revision 1.54 1999/03/02 22:52:20 peter
  704. * fixed char array, which can start with all possible values
  705. Revision 1.53 1999/02/25 21:02:57 peter
  706. * ag386bin updates
  707. + coff writer
  708. Revision 1.52 1999/02/24 09:51:44 florian
  709. * wrong warning fixed, if a non-virtual method was hidden by a virtual
  710. method (repoerted by Matthias Koeppe)
  711. Revision 1.51 1999/02/22 23:33:31 florian
  712. + message directive for integers added
  713. Revision 1.50 1999/02/22 20:13:42 florian
  714. + first implementation of message keyword
  715. Revision 1.49 1999/02/16 00:45:30 peter
  716. * fixed crashes by forgotten strpnew() for init_symbol
  717. Revision 1.48 1999/02/09 23:03:08 florian
  718. * check for duplicate field names in inherited classes/objects
  719. * bug with self from the mailing list solved (the problem
  720. was that classes were sometimes pushed wrong)
  721. Revision 1.47 1999/01/27 00:14:01 florian
  722. * "procedure of object"-stuff fixed
  723. Revision 1.46 1999/01/21 22:10:54 peter
  724. * fixed array of const
  725. * generic platform independent high() support
  726. Revision 1.45 1999/01/20 12:34:22 peter
  727. * fixed typed file read/write
  728. Revision 1.44 1999/01/15 11:33:03 pierre
  729. * bug in mmx code removed
  730. Revision 1.43 1998/12/30 13:41:20 peter
  731. * released valuepara
  732. Revision 1.42 1998/12/11 00:04:03 peter
  733. + globtype,tokens,version unit splitted from globals
  734. Revision 1.41 1998/12/10 09:47:33 florian
  735. + basic operations with int64/qord (compiler with -dint64)
  736. + rtti of enumerations extended: names are now written
  737. Revision 1.40 1998/12/04 10:18:14 florian
  738. * some stuff for procedures of object added
  739. * bug with overridden virtual constructors fixed (reported by Italo Gomes)
  740. Revision 1.39 1998/11/27 14:50:55 peter
  741. + open strings, $P switch support
  742. Revision 1.38 1998/11/18 15:44:24 peter
  743. * VALUEPARA for tp7 compatible value parameters
  744. Revision 1.37 1998/11/13 10:15:50 peter
  745. * fixed ptr() with constants
  746. Revision 1.36 1998/11/10 10:09:21 peter
  747. * va_list -> array of const
  748. Revision 1.35 1998/10/19 08:55:13 pierre
  749. * wrong stabs info corrected once again !!
  750. + variable vmt offset with vmt field only if required
  751. implemented now !!!
  752. Revision 1.34 1998/10/12 09:50:06 florian
  753. + support of <procedure var type>:=<pointer> in delphi mode added
  754. Revision 1.33 1998/10/06 20:43:30 peter
  755. * fixed set of bugs. like set of false..true set of #1..#255 and
  756. set of #1..true which was allowed
  757. Revision 1.32 1998/10/05 21:33:35 peter
  758. * fixed 161,165,166,167,168
  759. Revision 1.31 1998/09/23 09:58:56 peter
  760. * first working array of const things
  761. Revision 1.30 1998/09/22 15:40:58 peter
  762. * some extra ifdef GDB
  763. Revision 1.29 1998/09/16 12:37:31 michael
  764. Added FPC_ prefix to abstracterror
  765. Revision 1.28 1998/09/09 16:44:23 florian
  766. * I hope, the case bug is fixed now
  767. Revision 1.27 1998/09/07 17:37:07 florian
  768. * first fixes for published properties
  769. Revision 1.26 1998/09/04 12:24:31 florian
  770. * bug0159 fixed
  771. Revision 1.25 1998/09/04 09:06:36 florian
  772. * bug0132 fixed
  773. Revision 1.24 1998/09/04 08:36:49 peter
  774. * fixed boolean:=integer which is not explicit
  775. Revision 1.23 1998/09/01 17:39:55 peter
  776. + internal constant functions
  777. Revision 1.22 1998/09/01 12:53:28 peter
  778. + aktpackenum
  779. Revision 1.21 1998/08/19 00:42:45 peter
  780. + subrange types for enums
  781. + checking for bounds type with ranges
  782. Revision 1.20 1998/08/18 14:17:14 pierre
  783. * bug about assigning the return value of a function to
  784. a procvar fixed : warning
  785. assigning a proc to a procvar need @ in FPC mode !!
  786. * missing file/line info restored
  787. Revision 1.19 1998/08/18 09:24:48 pierre
  788. * small warning position bug fixed
  789. * support_mmx switches splitting was missing
  790. * rhide error and warning output corrected
  791. Revision 1.18 1998/08/14 18:18:49 peter
  792. + dynamic set contruction
  793. * smallsets are now working (always longint size)
  794. Revision 1.17 1998/08/05 16:00:17 florian
  795. * some fixes for ansi strings
  796. Revision 1.16 1998/07/20 23:35:50 michael
  797. Const ansistrings are not copied.
  798. Revision 1.15 1998/07/18 22:54:32 florian
  799. * some ansi/wide/longstring support fixed:
  800. o parameter passing
  801. o returning as result from functions
  802. Revision 1.14 1998/06/12 14:50:50 peter
  803. * removed the tree dependency to types.pas
  804. * long_fil.pas support (not fully tested yet)
  805. Revision 1.13 1998/06/03 22:49:07 peter
  806. + wordbool,longbool
  807. * rename bis,von -> high,low
  808. * moved some systemunit loading/creating to psystem.pas
  809. Revision 1.12 1998/05/12 10:47:00 peter
  810. * moved printstatus to verb_def
  811. + V_Normal which is between V_Error and V_Warning and doesn't have a
  812. prefix like error: warning: and is included in V_Default
  813. * fixed some messages
  814. * first time parameter scan is only for -v and -T
  815. - removed old style messages
  816. Revision 1.11 1998/05/01 16:38:46 florian
  817. * handling of private and protected fixed
  818. + change_keywords_to_tp implemented to remove
  819. keywords which aren't supported by tp
  820. * break and continue are now symbols of the system unit
  821. + widestring, longstring and ansistring type released
  822. Revision 1.10 1998/04/29 10:34:08 pierre
  823. + added some code for ansistring (not complete nor working yet)
  824. * corrected operator overloading
  825. * corrected nasm output
  826. + started inline procedures
  827. + added starstarn : use ** for exponentiation (^ gave problems)
  828. + started UseTokenInfo cond to get accurate positions
  829. Revision 1.9 1998/04/21 10:16:49 peter
  830. * patches from strasbourg
  831. * objects is not used anymore in the fpc compiled version
  832. Revision 1.8 1998/04/12 22:39:44 florian
  833. * problem with read access to properties solved
  834. * correct handling of hidding methods via virtual (COM)
  835. * correct result type of constructor calls (COM), the resulttype
  836. depends now on the type of the class reference
  837. Revision 1.7 1998/04/10 21:36:56 florian
  838. + some stuff to support method pointers (procedure of object) added
  839. (declaration, parameter handling)
  840. Revision 1.6 1998/04/10 15:39:49 florian
  841. * more fixes to get classes.pas compiled
  842. Revision 1.5 1998/04/09 23:02:16 florian
  843. * small problems solved to get remake3 work
  844. Revision 1.4 1998/04/08 16:58:09 pierre
  845. * several bugfixes
  846. ADD ADC and AND are also sign extended
  847. nasm output OK (program still crashes at end
  848. and creates wrong assembler files !!)
  849. procsym types sym in tdef removed !!
  850. Revision 1.3 1998/04/08 11:34:22 peter
  851. * nasm works (linux only tested)
  852. }