types.pas 39 KB

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