types.pas 34 KB

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