types.pas 39 KB

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