types.pas 78 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195
  1. {
  2. $Id$
  3. Copyright (C) 1998-2000 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. {$i defines.inc}
  20. interface
  21. uses
  22. cclasses,
  23. cpuinfo,
  24. node,
  25. symconst,symbase,symtype,symdef,symsym;
  26. type
  27. tmmxtype = (mmxno,mmxu8bit,mmxs8bit,mmxu16bit,mmxs16bit,
  28. mmxu32bit,mmxs32bit,mmxfixed16,mmxsingle);
  29. const
  30. { true if we must never copy this parameter }
  31. never_copy_const_param : boolean = false;
  32. {*****************************************************************************
  33. Basic type functions
  34. *****************************************************************************}
  35. { returns true, if def defines an ordinal type }
  36. function is_ordinal(def : tdef) : boolean;
  37. { returns the min. value of the type }
  38. function get_min_value(def : tdef) : longint;
  39. { returns basetype of the specified range }
  40. function range_to_basetype(low,high:TConstExprInt):tbasetype;
  41. { returns true, if def defines an ordinal type }
  42. function is_integer(def : tdef) : boolean;
  43. { true if p is a boolean }
  44. function is_boolean(def : tdef) : boolean;
  45. { true if p is a char }
  46. function is_char(def : tdef) : boolean;
  47. { true if p is a widechar }
  48. function is_widechar(def : tdef) : boolean;
  49. { true if p is a void}
  50. function is_void(def : tdef) : boolean;
  51. { true if p is a smallset def }
  52. function is_smallset(p : tdef) : boolean;
  53. { returns true, if def defines a signed data type (only for ordinal types) }
  54. function is_signed(def : tdef) : boolean;
  55. { returns whether def_from's range is comprised in def_to's if both are }
  56. { orddefs, false otherwise }
  57. function is_in_limit(def_from,def_to : tdef) : boolean;
  58. {*****************************************************************************
  59. Array helper functions
  60. *****************************************************************************}
  61. { true, if p points to a zero based (non special like open or
  62. dynamic array def, mainly this is used to see if the array
  63. is convertable to a pointer }
  64. function is_zero_based_array(p : tdef) : boolean;
  65. { true if p points to an open array def }
  66. function is_open_array(p : tdef) : boolean;
  67. { true if p points to a dynamic array def }
  68. function is_dynamic_array(p : tdef) : boolean;
  69. { true, if p points to an array of const def }
  70. function is_array_constructor(p : tdef) : boolean;
  71. { true, if p points to a variant array }
  72. function is_variant_array(p : tdef) : boolean;
  73. { true, if p points to an array of const }
  74. function is_array_of_const(p : tdef) : boolean;
  75. { true, if p points any kind of special array }
  76. function is_special_array(p : tdef) : boolean;
  77. { true if p is a char array def }
  78. function is_chararray(p : tdef) : boolean;
  79. { true if p is a wide char array def }
  80. function is_widechararray(p : tdef) : boolean;
  81. {*****************************************************************************
  82. String helper functions
  83. *****************************************************************************}
  84. { true if p points to an open string def }
  85. function is_open_string(p : tdef) : boolean;
  86. { true if p is an ansi string def }
  87. function is_ansistring(p : tdef) : boolean;
  88. { true if p is a long string def }
  89. function is_longstring(p : tdef) : boolean;
  90. { true if p is a wide string def }
  91. function is_widestring(p : tdef) : boolean;
  92. { true if p is a short string def }
  93. function is_shortstring(p : tdef) : boolean;
  94. { true if p is a pchar def }
  95. function is_pchar(p : tdef) : boolean;
  96. { true if p is a pwidechar def }
  97. function is_pwidechar(p : tdef) : boolean;
  98. { true if p is a voidpointer def }
  99. function is_voidpointer(p : tdef) : boolean;
  100. { returns true, if def uses FPU }
  101. function is_fpu(def : tdef) : boolean;
  102. { true if the return value is in EAX }
  103. function ret_in_acc(def : tdef) : boolean;
  104. { true if uses a parameter as return value }
  105. function ret_in_param(def : tdef) : boolean;
  106. { true, if def is a 64 bit int type }
  107. function is_64bitint(def : tdef) : boolean;
  108. function push_high_param(def : tdef) : boolean;
  109. { true if a parameter is too large to copy and only the address is pushed }
  110. function push_addr_param(def : tdef) : boolean;
  111. { true, if def1 and def2 are semantical the same }
  112. function is_equal(def1,def2 : tdef) : boolean;
  113. { checks for type compatibility (subgroups of type) }
  114. { used for case statements... probably missing stuff }
  115. { to use on other types }
  116. function is_subequal(def1, def2: tdef): boolean;
  117. type
  118. tconverttype = (
  119. tc_equal,
  120. tc_not_possible,
  121. tc_string_2_string,
  122. tc_char_2_string,
  123. tc_char_2_chararray,
  124. tc_pchar_2_string,
  125. tc_cchar_2_pchar,
  126. tc_cstring_2_pchar,
  127. tc_ansistring_2_pchar,
  128. tc_string_2_chararray,
  129. tc_chararray_2_string,
  130. tc_array_2_pointer,
  131. tc_pointer_2_array,
  132. tc_int_2_int,
  133. tc_int_2_bool,
  134. tc_bool_2_bool,
  135. tc_bool_2_int,
  136. tc_real_2_real,
  137. tc_int_2_real,
  138. tc_proc_2_procvar,
  139. tc_arrayconstructor_2_set,
  140. tc_load_smallset,
  141. tc_cord_2_pointer,
  142. tc_intf_2_string,
  143. tc_intf_2_guid,
  144. tc_class_2_intf,
  145. tc_char_2_char,
  146. tc_normal_2_smallset,
  147. tc_dynarray_2_openarray
  148. );
  149. function assignment_overloaded(from_def,to_def : tdef) : tprocdef;
  150. { Returns:
  151. 0 - Not convertable
  152. 1 - Convertable
  153. 2 - Convertable, but not first choice }
  154. function isconvertable(def_from,def_to : tdef;
  155. var doconv : tconverttype;
  156. fromtreetype : tnodetype;
  157. explicit : boolean) : byte;
  158. { same as is_equal, but with error message if failed }
  159. function CheckTypes(def1,def2 : tdef) : boolean;
  160. function equal_constsym(sym1,sym2:tconstsym):boolean;
  161. { true, if two parameter lists are equal }
  162. { if acp is cp_none, all have to match exactly }
  163. { if acp is cp_value_equal_const call by value }
  164. { and call by const parameter are assumed as }
  165. { equal }
  166. { if acp is cp_all the var const or nothing are considered equal }
  167. type
  168. compare_type = ( cp_none, cp_value_equal_const, cp_all);
  169. function equal_paras(paralist1,paralist2 : tlinkedlist; acp : compare_type) : boolean;
  170. { true if a type can be allowed for another one
  171. in a func var }
  172. function convertable_paras(paralist1,paralist2 : tlinkedlist; acp : compare_type) : boolean;
  173. { true if a function can be assigned to a procvar }
  174. { changed first argument type to pabstractprocdef so that it can also be }
  175. { used to test compatibility between two pprocvardefs (JM) }
  176. function proc_to_procvar_equal(def1:tabstractprocdef;def2:tprocvardef;exact:boolean) : boolean;
  177. function get_proc_2_procvar_def(p:tprocsym;d:tprocvardef):tprocdef;
  178. { if l isn't in the range of def a range check error (if not explicit) is generated and
  179. the value is placed within the range }
  180. procedure testrange(def : tdef;var l : tconstexprint;explicit:boolean);
  181. { returns the range of def }
  182. procedure getrange(def : tdef;var l : TConstExprInt;var h : TConstExprInt);
  183. { some type helper routines for MMX support }
  184. function is_mmx_able_array(p : tdef) : boolean;
  185. { returns the mmx type }
  186. function mmx_type(p : tdef) : tmmxtype;
  187. { returns true, if sym needs an entry in the proplist of a class rtti }
  188. function needs_prop_entry(sym : tsym) : boolean;
  189. implementation
  190. uses
  191. globtype,globals,systems,tokens,verbose,
  192. symtable;
  193. function needs_prop_entry(sym : tsym) : boolean;
  194. begin
  195. needs_prop_entry:=(sp_published in tsym(sym).symoptions) and
  196. (sym.typ in [propertysym,varsym]);
  197. end;
  198. function equal_constsym(sym1,sym2:tconstsym):boolean;
  199. var
  200. p1,p2,pend : pchar;
  201. begin
  202. equal_constsym:=false;
  203. if sym1.consttyp<>sym2.consttyp then
  204. exit;
  205. case sym1.consttyp of
  206. constint,
  207. constbool,
  208. constchar,
  209. constord :
  210. equal_constsym:=(sym1.valueord=sym2.valueord);
  211. constpointer :
  212. equal_constsym:=(sym1.valueordptr=sym2.valueordptr);
  213. conststring,constresourcestring :
  214. begin
  215. if sym1.len=sym2.len then
  216. begin
  217. p1:=pchar(sym1.valueptr);
  218. p2:=pchar(sym2.valueptr);
  219. pend:=p1+sym1.len;
  220. while (p1<pend) do
  221. begin
  222. if p1^<>p2^ then
  223. break;
  224. inc(p1);
  225. inc(p2);
  226. end;
  227. if (p1=pend) then
  228. equal_constsym:=true;
  229. end;
  230. end;
  231. constreal :
  232. equal_constsym:=(pbestreal(sym1.valueptr)^=pbestreal(sym2.valueptr)^);
  233. constset :
  234. equal_constsym:=(pnormalset(sym1.valueptr)^=pnormalset(sym2.valueptr)^);
  235. constnil :
  236. equal_constsym:=true;
  237. end;
  238. end;
  239. { compare_type = ( cp_none, cp_value_equal_const, cp_all); }
  240. function equal_paras(paralist1,paralist2 : TLinkedList; acp : compare_type) : boolean;
  241. var
  242. def1,def2 : TParaItem;
  243. begin
  244. def1:=TParaItem(paralist1.first);
  245. def2:=TParaItem(paralist2.first);
  246. while (assigned(def1)) and (assigned(def2)) do
  247. begin
  248. case acp of
  249. cp_value_equal_const :
  250. begin
  251. if not(is_equal(def1.paratype.def,def2.paratype.def)) or
  252. ((def1.paratyp<>def2.paratyp) and
  253. ((def1.paratyp in [vs_var,vs_out]) or
  254. (def2.paratyp in [vs_var,vs_out])
  255. )
  256. ) then
  257. begin
  258. equal_paras:=false;
  259. exit;
  260. end;
  261. end;
  262. cp_all :
  263. begin
  264. if not(is_equal(def1.paratype.def,def2.paratype.def)) or
  265. (def1.paratyp<>def2.paratyp) then
  266. begin
  267. equal_paras:=false;
  268. exit;
  269. end;
  270. end;
  271. cp_none :
  272. begin
  273. if not(is_equal(def1.paratype.def,def2.paratype.def)) then
  274. begin
  275. equal_paras:=false;
  276. exit;
  277. end;
  278. { also check default value if both have it declared }
  279. if assigned(def1.defaultvalue) and
  280. assigned(def2.defaultvalue) then
  281. begin
  282. if not equal_constsym(tconstsym(def1.defaultvalue),tconstsym(def2.defaultvalue)) then
  283. begin
  284. equal_paras:=false;
  285. exit;
  286. end;
  287. end;
  288. end;
  289. end;
  290. def1:=TParaItem(def1.next);
  291. def2:=TParaItem(def2.next);
  292. end;
  293. if (def1=nil) and (def2=nil) then
  294. equal_paras:=true
  295. else
  296. equal_paras:=false;
  297. end;
  298. function convertable_paras(paralist1,paralist2 : TLinkedList;acp : compare_type) : boolean;
  299. var
  300. def1,def2 : TParaItem;
  301. doconv : tconverttype;
  302. begin
  303. def1:=TParaItem(paralist1.first);
  304. def2:=TParaItem(paralist2.first);
  305. while (assigned(def1)) and (assigned(def2)) do
  306. begin
  307. case acp of
  308. cp_value_equal_const :
  309. begin
  310. if (isconvertable(def1.paratype.def,def2.paratype.def,doconv,callparan,false)=0) or
  311. ((def1.paratyp<>def2.paratyp) and
  312. ((def1.paratyp in [vs_out,vs_var]) or
  313. (def2.paratyp in [vs_out,vs_var])
  314. )
  315. ) then
  316. begin
  317. convertable_paras:=false;
  318. exit;
  319. end;
  320. end;
  321. cp_all :
  322. begin
  323. if (isconvertable(def1.paratype.def,def2.paratype.def,doconv,callparan,false)=0) or
  324. (def1.paratyp<>def2.paratyp) then
  325. begin
  326. convertable_paras:=false;
  327. exit;
  328. end;
  329. end;
  330. cp_none :
  331. begin
  332. if (isconvertable(def1.paratype.def,def2.paratype.def,doconv,callparan,false)=0) then
  333. begin
  334. convertable_paras:=false;
  335. exit;
  336. end;
  337. end;
  338. end;
  339. def1:=TParaItem(def1.next);
  340. def2:=TParaItem(def2.next);
  341. end;
  342. if (def1=nil) and (def2=nil) then
  343. convertable_paras:=true
  344. else
  345. convertable_paras:=false;
  346. end;
  347. { true if a function can be assigned to a procvar }
  348. { changed first argument type to pabstractprocdef so that it can also be }
  349. { used to test compatibility between two pprocvardefs (JM) }
  350. function proc_to_procvar_equal(def1:tabstractprocdef;def2:tprocvardef;exact:boolean) : boolean;
  351. const
  352. po_comp = po_compatibility_options-[po_methodpointer,po_classmethod];
  353. var
  354. ismethod : boolean;
  355. begin
  356. proc_to_procvar_equal:=false;
  357. if not(assigned(def1)) or not(assigned(def2)) then
  358. exit;
  359. { check for method pointer }
  360. if def1.deftype=procvardef then
  361. begin
  362. ismethod:=(po_methodpointer in def1.procoptions);
  363. end
  364. else
  365. begin
  366. ismethod:=assigned(def1.owner) and
  367. (def1.owner.symtabletype=objectsymtable);
  368. end;
  369. if (ismethod and not (po_methodpointer in def2.procoptions)) or
  370. (not(ismethod) and (po_methodpointer in def2.procoptions)) then
  371. begin
  372. Message(type_e_no_method_and_procedure_not_compatible);
  373. exit;
  374. end;
  375. { check return value and para's and options, methodpointer is already checked
  376. parameters may also be convertable }
  377. if is_equal(def1.rettype.def,def2.rettype.def) and
  378. (equal_paras(def1.para,def2.para,cp_all) or
  379. ((not exact) and convertable_paras(def1.para,def2.para,cp_all))) and
  380. ((po_comp * def1.procoptions)= (po_comp * def2.procoptions)) then
  381. proc_to_procvar_equal:=true
  382. else
  383. proc_to_procvar_equal:=false;
  384. end;
  385. function get_proc_2_procvar_def(p:tprocsym;d:tprocvardef):tprocdef;
  386. var
  387. matchprocdef : tprocdef;
  388. pd : pprocdeflist;
  389. begin
  390. { This function will return the pprocdef of pprocsym that
  391. is the best match for procvardef. When there are multiple
  392. matches it returns nil }
  393. { exact match }
  394. matchprocdef:=nil;
  395. pd:=p.defs;
  396. while assigned(pd) do
  397. begin
  398. if proc_to_procvar_equal(pd^.def,d,true) then
  399. begin
  400. { already found a match ? Then stop and return nil }
  401. if assigned(matchprocdef) then
  402. begin
  403. matchprocdef:=nil;
  404. break;
  405. end;
  406. matchprocdef:=pd^.def;
  407. end;
  408. pd:=pd^.next;
  409. end;
  410. { convertable match, if no exact match was found }
  411. if not assigned(matchprocdef) and
  412. not assigned(pd) then
  413. begin
  414. pd:=p.defs;
  415. while assigned(pd) do
  416. begin
  417. if proc_to_procvar_equal(pd^.def,d,false) then
  418. begin
  419. { already found a match ? Then stop and return nil }
  420. if assigned(matchprocdef) then
  421. begin
  422. matchprocdef:=nil;
  423. break;
  424. end;
  425. matchprocdef:=pd^.def;
  426. end;
  427. pd:=pd^.next;
  428. end;
  429. end;
  430. get_proc_2_procvar_def:=matchprocdef;
  431. end;
  432. { returns true, if def uses FPU }
  433. function is_fpu(def : tdef) : boolean;
  434. begin
  435. is_fpu:=(def.deftype=floatdef);
  436. end;
  437. function range_to_basetype(low,high:TConstExprInt):tbasetype;
  438. begin
  439. { generate a unsigned range if high<0 and low>=0 }
  440. if (low>=0) and (high<0) then
  441. range_to_basetype:=u32bit
  442. else if (low>=0) and (high<=255) then
  443. range_to_basetype:=u8bit
  444. else if (low>=-128) and (high<=127) then
  445. range_to_basetype:=s8bit
  446. else if (low>=0) and (high<=65536) then
  447. range_to_basetype:=u16bit
  448. else if (low>=-32768) and (high<=32767) then
  449. range_to_basetype:=s16bit
  450. else
  451. range_to_basetype:=s32bit;
  452. end;
  453. { true if p is an ordinal }
  454. function is_ordinal(def : tdef) : boolean;
  455. var
  456. dt : tbasetype;
  457. begin
  458. case def.deftype of
  459. orddef :
  460. begin
  461. dt:=torddef(def).typ;
  462. is_ordinal:=dt in [uchar,uwidechar,
  463. u8bit,u16bit,u32bit,u64bit,
  464. s8bit,s16bit,s32bit,s64bit,
  465. bool8bit,bool16bit,bool32bit];
  466. end;
  467. enumdef :
  468. is_ordinal:=true;
  469. else
  470. is_ordinal:=false;
  471. end;
  472. end;
  473. { returns the min. value of the type }
  474. function get_min_value(def : tdef) : longint;
  475. begin
  476. case def.deftype of
  477. orddef:
  478. get_min_value:=torddef(def).low;
  479. enumdef:
  480. get_min_value:=tenumdef(def).min;
  481. else
  482. get_min_value:=0;
  483. end;
  484. end;
  485. { true if p is an integer }
  486. function is_integer(def : tdef) : boolean;
  487. begin
  488. is_integer:=(def.deftype=orddef) and
  489. (torddef(def).typ in [u8bit,u16bit,u32bit,u64bit,
  490. s8bit,s16bit,s32bit,s64bit]);
  491. end;
  492. { true if p is a boolean }
  493. function is_boolean(def : tdef) : boolean;
  494. begin
  495. is_boolean:=(def.deftype=orddef) and
  496. (torddef(def).typ in [bool8bit,bool16bit,bool32bit]);
  497. end;
  498. { true if p is a void }
  499. function is_void(def : tdef) : boolean;
  500. begin
  501. is_void:=(def.deftype=orddef) and
  502. (torddef(def).typ=uvoid);
  503. end;
  504. { true if p is a char }
  505. function is_char(def : tdef) : boolean;
  506. begin
  507. is_char:=(def.deftype=orddef) and
  508. (torddef(def).typ=uchar);
  509. end;
  510. { true if p is a wchar }
  511. function is_widechar(def : tdef) : boolean;
  512. begin
  513. is_widechar:=(def.deftype=orddef) and
  514. (torddef(def).typ=uwidechar);
  515. end;
  516. { true if p is signed (integer) }
  517. function is_signed(def : tdef) : boolean;
  518. var
  519. dt : tbasetype;
  520. begin
  521. case def.deftype of
  522. orddef :
  523. begin
  524. dt:=torddef(def).typ;
  525. is_signed:=(dt in [s8bit,s16bit,s32bit,s64bit]);
  526. end;
  527. enumdef :
  528. is_signed:=tenumdef(def).min < 0;
  529. arraydef :
  530. is_signed:=is_signed(tarraydef(def).rangetype.def);
  531. else
  532. is_signed:=false;
  533. end;
  534. end;
  535. function is_in_limit(def_from,def_to : tdef) : boolean;
  536. var
  537. fromqword, toqword: boolean;
  538. begin
  539. if (def_from.deftype <> orddef) or
  540. (def_to.deftype <> orddef) then
  541. begin
  542. is_in_limit := false;
  543. exit;
  544. end;
  545. fromqword := torddef(def_from).typ = u64bit;
  546. toqword := torddef(def_to).typ = u64bit;
  547. is_in_limit:=((not(fromqword xor toqword) and
  548. (torddef(def_from).low>=torddef(def_to).low) and
  549. (torddef(def_from).high<=torddef(def_to).high)) or
  550. (toqword and not is_signed(def_from)));
  551. end;
  552. { true, if p points to an open array def }
  553. function is_open_string(p : tdef) : boolean;
  554. begin
  555. is_open_string:=(p.deftype=stringdef) and
  556. (tstringdef(p).string_typ=st_shortstring) and
  557. (tstringdef(p).len=0);
  558. end;
  559. { true, if p points to a zero based array def }
  560. function is_zero_based_array(p : tdef) : boolean;
  561. begin
  562. is_zero_based_array:=(p.deftype=arraydef) and
  563. (tarraydef(p).lowrange=0) and
  564. not(is_special_array(p));
  565. end;
  566. { true if p points to a dynamic array def }
  567. function is_dynamic_array(p : tdef) : boolean;
  568. begin
  569. is_dynamic_array:=(p.deftype=arraydef) and
  570. tarraydef(p).IsDynamicArray;
  571. end;
  572. { true, if p points to an open array def }
  573. function is_open_array(p : tdef) : boolean;
  574. begin
  575. { check for s32bittype is needed, because for u32bit the high
  576. range is also -1 ! (PFV) }
  577. is_open_array:=(p.deftype=arraydef) and
  578. (tarraydef(p).rangetype.def=s32bittype.def) and
  579. (tarraydef(p).lowrange=0) and
  580. (tarraydef(p).highrange=-1) and
  581. not(tarraydef(p).IsConstructor) and
  582. not(tarraydef(p).IsVariant) and
  583. not(tarraydef(p).IsArrayOfConst) and
  584. not(tarraydef(p).IsDynamicArray);
  585. end;
  586. { true, if p points to an array of const def }
  587. function is_array_constructor(p : tdef) : boolean;
  588. begin
  589. is_array_constructor:=(p.deftype=arraydef) and
  590. (tarraydef(p).IsConstructor);
  591. end;
  592. { true, if p points to a variant array }
  593. function is_variant_array(p : tdef) : boolean;
  594. begin
  595. is_variant_array:=(p.deftype=arraydef) and
  596. (tarraydef(p).IsVariant);
  597. end;
  598. { true, if p points to an array of const }
  599. function is_array_of_const(p : tdef) : boolean;
  600. begin
  601. is_array_of_const:=(p.deftype=arraydef) and
  602. (tarraydef(p).IsArrayOfConst);
  603. end;
  604. { true, if p points to a special array }
  605. function is_special_array(p : tdef) : boolean;
  606. begin
  607. is_special_array:=(p.deftype=arraydef) and
  608. ((tarraydef(p).IsVariant) or
  609. (tarraydef(p).IsArrayOfConst) or
  610. (tarraydef(p).IsConstructor) or
  611. is_open_array(p)
  612. );
  613. end;
  614. { true if p is an ansi string def }
  615. function is_ansistring(p : tdef) : boolean;
  616. begin
  617. is_ansistring:=(p.deftype=stringdef) and
  618. (tstringdef(p).string_typ=st_ansistring);
  619. end;
  620. { true if p is an long string def }
  621. function is_longstring(p : tdef) : boolean;
  622. begin
  623. is_longstring:=(p.deftype=stringdef) and
  624. (tstringdef(p).string_typ=st_longstring);
  625. end;
  626. { true if p is an wide string def }
  627. function is_widestring(p : tdef) : boolean;
  628. begin
  629. is_widestring:=(p.deftype=stringdef) and
  630. (tstringdef(p).string_typ=st_widestring);
  631. end;
  632. { true if p is an short string def }
  633. function is_shortstring(p : tdef) : boolean;
  634. begin
  635. is_shortstring:=(p.deftype=stringdef) and
  636. (tstringdef(p).string_typ=st_shortstring);
  637. end;
  638. { true if p is a char array def }
  639. function is_chararray(p : tdef) : boolean;
  640. begin
  641. is_chararray:=(p.deftype=arraydef) and
  642. is_equal(tarraydef(p).elementtype.def,cchartype.def) and
  643. not(is_special_array(p));
  644. end;
  645. { true if p is a widechar array def }
  646. function is_widechararray(p : tdef) : boolean;
  647. begin
  648. is_widechararray:=(p.deftype=arraydef) and
  649. is_equal(tarraydef(p).elementtype.def,cwidechartype.def) and
  650. not(is_special_array(p));
  651. end;
  652. { true if p is a pchar def }
  653. function is_pchar(p : tdef) : boolean;
  654. begin
  655. is_pchar:=(p.deftype=pointerdef) and
  656. (is_equal(tpointerdef(p).pointertype.def,cchartype.def) or
  657. (is_zero_based_array(tpointerdef(p).pointertype.def) and
  658. is_chararray(tpointerdef(p).pointertype.def)));
  659. end;
  660. { true if p is a pchar def }
  661. function is_pwidechar(p : tdef) : boolean;
  662. begin
  663. is_pwidechar:=(p.deftype=pointerdef) and
  664. (is_equal(tpointerdef(p).pointertype.def,cwidechartype.def) or
  665. (is_zero_based_array(tpointerdef(p).pointertype.def) and
  666. is_widechararray(tpointerdef(p).pointertype.def)));
  667. end;
  668. { true if p is a voidpointer def }
  669. function is_voidpointer(p : tdef) : boolean;
  670. begin
  671. is_voidpointer:=(p.deftype=pointerdef) and
  672. (tpointerdef(p).pointertype.def.deftype=orddef) and
  673. (torddef(tpointerdef(p).pointertype.def).typ=uvoid);
  674. end;
  675. { true if p is a smallset def }
  676. function is_smallset(p : tdef) : boolean;
  677. begin
  678. is_smallset:=(p.deftype=setdef) and
  679. (tsetdef(p).settype=smallset);
  680. end;
  681. { true if the return value is in accumulator (EAX for i386), D0 for 68k }
  682. function ret_in_acc(def : tdef) : boolean;
  683. begin
  684. ret_in_acc:=(def.deftype in [orddef,pointerdef,enumdef,classrefdef]) or
  685. ((def.deftype=stringdef) and (tstringdef(def).string_typ in [st_ansistring,st_widestring])) or
  686. ((def.deftype=procvardef) and not(po_methodpointer in tprocvardef(def).procoptions)) or
  687. ((def.deftype=objectdef) and not is_object(def)) or
  688. ((def.deftype=setdef) and (tsetdef(def).settype=smallset));
  689. end;
  690. { true, if def is a 64 bit int type }
  691. function is_64bitint(def : tdef) : boolean;
  692. begin
  693. is_64bitint:=(def.deftype=orddef) and (torddef(def).typ in [u64bit,s64bit])
  694. end;
  695. { true if uses a parameter as return value }
  696. function ret_in_param(def : tdef) : boolean;
  697. begin
  698. ret_in_param:=(def.deftype in [arraydef,recorddef]) or
  699. ((def.deftype=stringdef) and (tstringdef(def).string_typ in [st_shortstring,st_longstring])) or
  700. ((def.deftype=procvardef) and (po_methodpointer in tprocvardef(def).procoptions)) or
  701. ((def.deftype=objectdef) and is_object(def)) or
  702. (def.deftype=variantdef) or
  703. ((def.deftype=setdef) and (tsetdef(def).settype<>smallset));
  704. end;
  705. function push_high_param(def : tdef) : boolean;
  706. begin
  707. push_high_param:=is_open_array(def) or
  708. is_open_string(def) or
  709. is_array_of_const(def);
  710. end;
  711. { true if a parameter is too large to copy and only the address is pushed }
  712. function push_addr_param(def : tdef) : boolean;
  713. begin
  714. push_addr_param:=false;
  715. if never_copy_const_param then
  716. push_addr_param:=true
  717. else
  718. begin
  719. case def.deftype of
  720. variantdef,
  721. formaldef :
  722. push_addr_param:=true;
  723. recorddef :
  724. push_addr_param:=(def.size>target_info.size_of_pointer);
  725. arraydef :
  726. push_addr_param:=((tarraydef(def).highrange>=tarraydef(def).lowrange) and (def.size>target_info.size_of_pointer)) or
  727. is_open_array(def) or
  728. is_array_of_const(def) or
  729. is_array_constructor(def);
  730. objectdef :
  731. push_addr_param:=is_object(def);
  732. stringdef :
  733. push_addr_param:=tstringdef(def).string_typ in [st_shortstring,st_longstring];
  734. procvardef :
  735. push_addr_param:=(po_methodpointer in tprocvardef(def).procoptions);
  736. setdef :
  737. push_addr_param:=(tsetdef(def).settype<>smallset);
  738. end;
  739. end;
  740. end;
  741. { if l isn't in the range of def a range check error (if not explicit) is generated and
  742. the value is placed within the range }
  743. procedure testrange(def : tdef;var l : tconstexprint;explicit:boolean);
  744. var
  745. lv,hv: TConstExprInt;
  746. error: boolean;
  747. begin
  748. error := false;
  749. { for 64 bit types we need only to check if it is less than }
  750. { zero, if def is a qword node }
  751. if is_64bitint(def) then
  752. begin
  753. if (l<0) and (torddef(def).typ=u64bit) then
  754. begin
  755. { don't zero the result, because it may come from hex notation
  756. like $ffffffffffffffff! (JM)
  757. l:=0; }
  758. if not explicit then
  759. begin
  760. if (cs_check_range in aktlocalswitches) then
  761. Message(parser_e_range_check_error)
  762. else
  763. Message(parser_w_range_check_error);
  764. end;
  765. error := true;
  766. end;
  767. end
  768. else
  769. begin
  770. getrange(def,lv,hv);
  771. if (def.deftype=orddef) and
  772. (torddef(def).typ=u32bit) then
  773. begin
  774. if (l < cardinal(lv)) or
  775. (l > cardinal(hv)) then
  776. begin
  777. if not explicit then
  778. begin
  779. if (cs_check_range in aktlocalswitches) then
  780. Message(parser_e_range_check_error)
  781. else
  782. Message(parser_w_range_check_error);
  783. end;
  784. error := true;
  785. end;
  786. end
  787. else if (l<lv) or (l>hv) then
  788. begin
  789. if not explicit then
  790. begin
  791. if ((def.deftype=enumdef) and
  792. { delphi allows range check errors in
  793. enumeration type casts FK }
  794. not(m_delphi in aktmodeswitches)) or
  795. (cs_check_range in aktlocalswitches) then
  796. Message(parser_e_range_check_error)
  797. else
  798. Message(parser_w_range_check_error);
  799. end;
  800. error := true;
  801. end;
  802. end;
  803. if error then
  804. begin
  805. { Fix the value to fit in the allocated space for this type of variable }
  806. case def.size of
  807. 1: l := l and $ff;
  808. 2: l := l and $ffff;
  809. { work around sign extension bug (to be fixed) (JM) }
  810. 4: l := l and (int64($fffffff) shl 4 + $f);
  811. end;
  812. { do sign extension if necessary (JM) }
  813. if is_signed(def) then
  814. begin
  815. case def.size of
  816. 1: l := shortint(l);
  817. 2: l := smallint(l);
  818. 4: l := longint(l);
  819. end;
  820. end;
  821. end;
  822. end;
  823. { return the range from def in l and h }
  824. procedure getrange(def : tdef;var l : TConstExprInt;var h : TConstExprInt);
  825. begin
  826. case def.deftype of
  827. orddef :
  828. begin
  829. l:=torddef(def).low;
  830. h:=torddef(def).high;
  831. end;
  832. enumdef :
  833. begin
  834. l:=tenumdef(def).min;
  835. h:=tenumdef(def).max;
  836. end;
  837. arraydef :
  838. begin
  839. l:=tarraydef(def).lowrange;
  840. h:=tarraydef(def).highrange;
  841. end;
  842. else
  843. internalerror(987);
  844. end;
  845. end;
  846. function mmx_type(p : tdef) : tmmxtype;
  847. begin
  848. mmx_type:=mmxno;
  849. if is_mmx_able_array(p) then
  850. begin
  851. if tarraydef(p).elementtype.def.deftype=floatdef then
  852. case tfloatdef(tarraydef(p).elementtype.def).typ of
  853. s32real:
  854. mmx_type:=mmxsingle;
  855. end
  856. else
  857. case torddef(tarraydef(p).elementtype.def).typ of
  858. u8bit:
  859. mmx_type:=mmxu8bit;
  860. s8bit:
  861. mmx_type:=mmxs8bit;
  862. u16bit:
  863. mmx_type:=mmxu16bit;
  864. s16bit:
  865. mmx_type:=mmxs16bit;
  866. u32bit:
  867. mmx_type:=mmxu32bit;
  868. s32bit:
  869. mmx_type:=mmxs32bit;
  870. end;
  871. end;
  872. end;
  873. function is_mmx_able_array(p : tdef) : boolean;
  874. begin
  875. {$ifdef SUPPORT_MMX}
  876. if (cs_mmx_saturation in aktlocalswitches) then
  877. begin
  878. is_mmx_able_array:=(p.deftype=arraydef) and
  879. not(is_special_array(p)) and
  880. (
  881. (
  882. (tarraydef(p).elementtype.def.deftype=orddef) and
  883. (
  884. (
  885. (tarraydef(p).lowrange=0) and
  886. (tarraydef(p).highrange=1) and
  887. (torddef(tarraydef(p).elementtype.def).typ in [u32bit,s32bit])
  888. )
  889. or
  890. (
  891. (tarraydef(p).lowrange=0) and
  892. (tarraydef(p).highrange=3) and
  893. (torddef(tarraydef(p).elementtype.def).typ in [u16bit,s16bit])
  894. )
  895. )
  896. )
  897. or
  898. (
  899. (
  900. (tarraydef(p).elementtype.def.deftype=floatdef) and
  901. (
  902. (tarraydef(p).lowrange=0) and
  903. (tarraydef(p).highrange=1) and
  904. (tfloatdef(tarraydef(p).elementtype.def).typ=s32real)
  905. )
  906. )
  907. )
  908. );
  909. end
  910. else
  911. begin
  912. is_mmx_able_array:=(p.deftype=arraydef) and
  913. (
  914. (
  915. (tarraydef(p).elementtype.def.deftype=orddef) and
  916. (
  917. (
  918. (tarraydef(p).lowrange=0) and
  919. (tarraydef(p).highrange=1) and
  920. (torddef(tarraydef(p).elementtype.def).typ in [u32bit,s32bit])
  921. )
  922. or
  923. (
  924. (tarraydef(p).lowrange=0) and
  925. (tarraydef(p).highrange=3) and
  926. (torddef(tarraydef(p).elementtype.def).typ in [u16bit,s16bit])
  927. )
  928. or
  929. (
  930. (tarraydef(p).lowrange=0) and
  931. (tarraydef(p).highrange=7) and
  932. (torddef(tarraydef(p).elementtype.def).typ in [u8bit,s8bit])
  933. )
  934. )
  935. )
  936. or
  937. (
  938. (tarraydef(p).elementtype.def.deftype=floatdef) and
  939. (
  940. (tarraydef(p).lowrange=0) and
  941. (tarraydef(p).highrange=1) and
  942. (tfloatdef(tarraydef(p).elementtype.def).typ=s32real)
  943. )
  944. )
  945. );
  946. end;
  947. {$else SUPPORT_MMX}
  948. is_mmx_able_array:=false;
  949. {$endif SUPPORT_MMX}
  950. end;
  951. function is_equal(def1,def2 : tdef) : boolean;
  952. var
  953. b : boolean;
  954. hd : tdef;
  955. begin
  956. { both types must exists }
  957. if not (assigned(def1) and assigned(def2)) then
  958. begin
  959. is_equal:=false;
  960. exit;
  961. end;
  962. { be sure, that if there is a stringdef, that this is def1 }
  963. if def2.deftype=stringdef then
  964. begin
  965. hd:=def1;
  966. def1:=def2;
  967. def2:=hd;
  968. end;
  969. b:=false;
  970. { both point to the same definition ? }
  971. if def1=def2 then
  972. b:=true
  973. else
  974. { pointer with an equal definition are equal }
  975. if (def1.deftype=pointerdef) and (def2.deftype=pointerdef) then
  976. begin
  977. { check if both are farpointer }
  978. if (tpointerdef(def1).is_far=tpointerdef(def2).is_far) then
  979. begin
  980. { here a problem detected in tabsolutesym }
  981. { the types can be forward type !! }
  982. if assigned(def1.typesym) and (tpointerdef(def1).pointertype.def.deftype=forwarddef) then
  983. b:=(def1.typesym=def2.typesym)
  984. else
  985. b:=tpointerdef(def1).pointertype.def=tpointerdef(def2).pointertype.def;
  986. end
  987. else
  988. b:=false;
  989. end
  990. else
  991. { ordinals are equal only when the ordinal type is equal }
  992. if (def1.deftype=orddef) and (def2.deftype=orddef) then
  993. begin
  994. case torddef(def1).typ of
  995. u8bit,u16bit,u32bit,
  996. s8bit,s16bit,s32bit:
  997. b:=((torddef(def1).typ=torddef(def2).typ) and
  998. (torddef(def1).low=torddef(def2).low) and
  999. (torddef(def1).high=torddef(def2).high));
  1000. uvoid,uchar,uwidechar,
  1001. bool8bit,bool16bit,bool32bit:
  1002. b:=(torddef(def1).typ=torddef(def2).typ);
  1003. end;
  1004. end
  1005. else
  1006. if (def1.deftype=floatdef) and (def2.deftype=floatdef) then
  1007. b:=tfloatdef(def1).typ=tfloatdef(def2).typ
  1008. else
  1009. { strings with the same length are equal }
  1010. if (def1.deftype=stringdef) and (def2.deftype=stringdef) and
  1011. (tstringdef(def1).string_typ=tstringdef(def2).string_typ) then
  1012. begin
  1013. b:=not(is_shortstring(def1)) or
  1014. (tstringdef(def1).len=tstringdef(def2).len);
  1015. end
  1016. else
  1017. if (def1.deftype=formaldef) and (def2.deftype=formaldef) then
  1018. b:=true
  1019. { file types with the same file element type are equal }
  1020. { this is a problem for assign !! }
  1021. { changed to allow if one is untyped }
  1022. { all typed files are equal to the special }
  1023. { typed file that has voiddef as elemnt type }
  1024. { but must NOT match for text file !!! }
  1025. else
  1026. if (def1.deftype=filedef) and (def2.deftype=filedef) then
  1027. b:=(tfiledef(def1).filetyp=tfiledef(def2).filetyp) and
  1028. ((
  1029. ((tfiledef(def1).typedfiletype.def=nil) and
  1030. (tfiledef(def2).typedfiletype.def=nil)) or
  1031. (
  1032. (tfiledef(def1).typedfiletype.def<>nil) and
  1033. (tfiledef(def2).typedfiletype.def<>nil) and
  1034. is_equal(tfiledef(def1).typedfiletype.def,tfiledef(def2).typedfiletype.def)
  1035. ) or
  1036. ( (tfiledef(def1).typedfiletype.def=tdef(voidtype.def)) or
  1037. (tfiledef(def2).typedfiletype.def=tdef(voidtype.def))
  1038. )))
  1039. { sets with the same element base type are equal }
  1040. else
  1041. if (def1.deftype=setdef) and (def2.deftype=setdef) then
  1042. begin
  1043. if assigned(tsetdef(def1).elementtype.def) and
  1044. assigned(tsetdef(def2).elementtype.def) then
  1045. b:=is_subequal(tsetdef(def1).elementtype.def,tsetdef(def2).elementtype.def)
  1046. else
  1047. { empty set is compatible with everything }
  1048. b:=true;
  1049. end
  1050. else
  1051. if (def1.deftype=procvardef) and (def2.deftype=procvardef) then
  1052. begin
  1053. { poassembler isn't important for compatibility }
  1054. { if a method is assigned to a methodpointer }
  1055. { is checked before }
  1056. b:=(tprocvardef(def1).proctypeoption=tprocvardef(def2).proctypeoption) and
  1057. (tprocvardef(def1).proccalloption=tprocvardef(def2).proccalloption) and
  1058. ((tprocvardef(def1).procoptions * po_compatibility_options)=
  1059. (tprocvardef(def2).procoptions * po_compatibility_options)) and
  1060. is_equal(tprocvardef(def1).rettype.def,tprocvardef(def2).rettype.def) and
  1061. equal_paras(tprocvardef(def1).para,tprocvardef(def2).para,cp_all);
  1062. end
  1063. else
  1064. if (def1.deftype=arraydef) and (def2.deftype=arraydef) then
  1065. begin
  1066. if is_dynamic_array(def1) and is_dynamic_array(def2) then
  1067. b:=is_equal(tarraydef(def1).elementtype.def,tarraydef(def2).elementtype.def)
  1068. else
  1069. if is_array_of_const(def1) or is_array_of_const(def2) then
  1070. begin
  1071. b:=(is_array_of_const(def1) and is_array_of_const(def2)) or
  1072. (is_array_of_const(def1) and is_array_constructor(def2)) or
  1073. (is_array_of_const(def2) and is_array_constructor(def1));
  1074. end
  1075. else
  1076. if (is_dynamic_array(def1) or is_dynamic_array(def2)) then
  1077. begin
  1078. b := is_dynamic_array(def1) and is_dynamic_array(def2) and
  1079. is_equal(tarraydef(def1).elementtype.def,tarraydef(def2).elementtype.def);
  1080. end
  1081. else
  1082. if is_open_array(def1) or is_open_array(def2) then
  1083. begin
  1084. b:=is_equal(tarraydef(def1).elementtype.def,tarraydef(def2).elementtype.def);
  1085. end
  1086. else
  1087. begin
  1088. b:=not(m_tp7 in aktmodeswitches) and
  1089. not(m_delphi in aktmodeswitches) and
  1090. (tarraydef(def1).lowrange=tarraydef(def2).lowrange) and
  1091. (tarraydef(def1).highrange=tarraydef(def2).highrange) and
  1092. is_equal(tarraydef(def1).elementtype.def,tarraydef(def2).elementtype.def) and
  1093. is_equal(tarraydef(def1).rangetype.def,tarraydef(def2).rangetype.def);
  1094. end;
  1095. end
  1096. else
  1097. if (def1.deftype=classrefdef) and (def2.deftype=classrefdef) then
  1098. begin
  1099. { similar to pointerdef: }
  1100. if assigned(def1.typesym) and (tclassrefdef(def1).pointertype.def.deftype=forwarddef) then
  1101. b:=(def1.typesym=def2.typesym)
  1102. else
  1103. b:=is_equal(tclassrefdef(def1).pointertype.def,tclassrefdef(def2).pointertype.def);
  1104. end;
  1105. is_equal:=b;
  1106. end;
  1107. function is_subequal(def1, def2: tdef): boolean;
  1108. var
  1109. basedef1,basedef2 : tenumdef;
  1110. Begin
  1111. is_subequal := false;
  1112. if assigned(def1) and assigned(def2) then
  1113. Begin
  1114. if (def1.deftype = orddef) and (def2.deftype = orddef) then
  1115. Begin
  1116. { see p.47 of Turbo Pascal 7.01 manual for the separation of types }
  1117. { range checking for case statements is done with testrange }
  1118. case torddef(def1).typ of
  1119. u8bit,u16bit,u32bit,
  1120. s8bit,s16bit,s32bit,s64bit,u64bit :
  1121. is_subequal:=(torddef(def2).typ in [s64bit,u64bit,s32bit,u32bit,u8bit,s8bit,s16bit,u16bit]);
  1122. bool8bit,bool16bit,bool32bit :
  1123. is_subequal:=(torddef(def2).typ in [bool8bit,bool16bit,bool32bit]);
  1124. uchar :
  1125. is_subequal:=(torddef(def2).typ=uchar);
  1126. uwidechar :
  1127. is_subequal:=(torddef(def2).typ=uwidechar);
  1128. end;
  1129. end
  1130. else
  1131. Begin
  1132. { I assume that both enumerations are equal when the first }
  1133. { pointers are equal. }
  1134. { I changed this to assume that the enums are equal }
  1135. { if the basedefs are equal (FK) }
  1136. if (def1.deftype=enumdef) and (def2.deftype=enumdef) then
  1137. Begin
  1138. { get both basedefs }
  1139. basedef1:=tenumdef(def1);
  1140. while assigned(basedef1.basedef) do
  1141. basedef1:=basedef1.basedef;
  1142. basedef2:=tenumdef(def2);
  1143. while assigned(basedef2.basedef) do
  1144. basedef2:=basedef2.basedef;
  1145. is_subequal:=basedef1=basedef2;
  1146. {
  1147. if tenumdef(def1).firstenum = tenumdef(def2).firstenum then
  1148. is_subequal := TRUE;
  1149. }
  1150. end;
  1151. end;
  1152. end; { endif assigned ... }
  1153. end;
  1154. function assignment_overloaded(from_def,to_def : tdef) : tprocdef;
  1155. var
  1156. passprocs : pprocdeflist;
  1157. convtyp : tconverttype;
  1158. begin
  1159. assignment_overloaded:=nil;
  1160. if not assigned(overloaded_operators[_ASSIGNMENT]) then
  1161. exit;
  1162. { look for an exact match first }
  1163. passprocs:=overloaded_operators[_ASSIGNMENT].defs;
  1164. while assigned(passprocs) do
  1165. begin
  1166. if is_equal(passprocs^.def.rettype.def,to_def) and
  1167. (TParaItem(passprocs^.def.Para.first).paratype.def=from_def) then
  1168. begin
  1169. assignment_overloaded:=passprocs^.def;
  1170. exit;
  1171. end;
  1172. passprocs:=passprocs^.next;
  1173. end;
  1174. { .... then look for an equal match }
  1175. passprocs:=overloaded_operators[_ASSIGNMENT].defs;
  1176. while assigned(passprocs) do
  1177. begin
  1178. if is_equal(passprocs^.def.rettype.def,to_def) and
  1179. is_equal(TParaItem(passprocs^.def.Para.first).paratype.def,from_def) then
  1180. begin
  1181. assignment_overloaded:=passprocs^.def;
  1182. exit;
  1183. end;
  1184. passprocs:=passprocs^.next;
  1185. end;
  1186. { .... then for convert level 1 }
  1187. passprocs:=overloaded_operators[_ASSIGNMENT].defs;
  1188. while assigned(passprocs) do
  1189. begin
  1190. if is_equal(passprocs^.def.rettype.def,to_def) and
  1191. (isconvertable(from_def,TParaItem(passprocs^.def.Para.first).paratype.def,convtyp,ordconstn,false)=1) then
  1192. begin
  1193. assignment_overloaded:=passprocs^.def;
  1194. exit;
  1195. end;
  1196. passprocs:=passprocs^.next;
  1197. end;
  1198. end;
  1199. { Returns:
  1200. 0 - Not convertable
  1201. 1 - Convertable
  1202. 2 - Convertable, but not first choice }
  1203. function isconvertable(def_from,def_to : tdef;
  1204. var doconv : tconverttype;
  1205. fromtreetype : tnodetype;
  1206. explicit : boolean) : byte;
  1207. { Tbasetype:
  1208. uvoid,
  1209. u8bit,u16bit,u32bit,u64bit,
  1210. s8bit,s16bit,s32bit,s64bit,
  1211. bool8bit,bool16bit,bool32bit,
  1212. uchar,uwidechar }
  1213. type
  1214. tbasedef=(bvoid,bchar,bint,bbool);
  1215. const
  1216. basedeftbl:array[tbasetype] of tbasedef =
  1217. (bvoid,
  1218. bint,bint,bint,bint,
  1219. bint,bint,bint,bint,
  1220. bbool,bbool,bbool,
  1221. bchar,bchar);
  1222. basedefconverts : array[tbasedef,tbasedef] of tconverttype =
  1223. ((tc_not_possible,tc_not_possible,tc_not_possible,tc_not_possible),
  1224. (tc_not_possible,tc_char_2_char,tc_not_possible,tc_not_possible),
  1225. (tc_not_possible,tc_not_possible,tc_int_2_int,tc_int_2_bool),
  1226. (tc_not_possible,tc_not_possible,tc_bool_2_int,tc_bool_2_bool));
  1227. var
  1228. b : byte;
  1229. hd1,hd2 : tdef;
  1230. hct : tconverttype;
  1231. begin
  1232. { safety check }
  1233. if not(assigned(def_from) and assigned(def_to)) then
  1234. begin
  1235. isconvertable:=0;
  1236. exit;
  1237. end;
  1238. { tp7 procvar def support, in tp7 a procvar is always called, if the
  1239. procvar is passed explicit a addrn would be there }
  1240. if (m_tp_procvar in aktmodeswitches) and
  1241. (def_from.deftype=procvardef) and
  1242. (fromtreetype=loadn) then
  1243. begin
  1244. def_from:=tprocvardef(def_from).rettype.def;
  1245. end;
  1246. { we walk the wanted (def_to) types and check then the def_from
  1247. types if there is a conversion possible }
  1248. b:=0;
  1249. case def_to.deftype of
  1250. orddef :
  1251. begin
  1252. case def_from.deftype of
  1253. orddef :
  1254. begin
  1255. doconv:=basedefconverts[basedeftbl[torddef(def_from).typ],basedeftbl[torddef(def_to).typ]];
  1256. b:=1;
  1257. if (doconv=tc_not_possible) or
  1258. ((doconv=tc_int_2_bool) and
  1259. (not explicit) and
  1260. (not is_boolean(def_from))) or
  1261. ((doconv=tc_bool_2_int) and
  1262. (not explicit) and
  1263. (not is_boolean(def_to))) then
  1264. b:=0
  1265. else
  1266. { "punish" bad type conversions :) (JM) }
  1267. if not is_in_limit(def_from,def_to) and
  1268. (def_from.size > def_to.size) then
  1269. b := 2;
  1270. end;
  1271. enumdef :
  1272. begin
  1273. { needed for char(enum) }
  1274. if explicit then
  1275. begin
  1276. doconv:=tc_int_2_int;
  1277. b:=1;
  1278. end;
  1279. end;
  1280. end;
  1281. end;
  1282. stringdef :
  1283. begin
  1284. case def_from.deftype of
  1285. stringdef :
  1286. begin
  1287. doconv:=tc_string_2_string;
  1288. b:=1;
  1289. end;
  1290. orddef :
  1291. begin
  1292. { char to string}
  1293. if is_char(def_from) or
  1294. is_widechar(def_from) then
  1295. begin
  1296. doconv:=tc_char_2_string;
  1297. b:=1;
  1298. end;
  1299. end;
  1300. arraydef :
  1301. begin
  1302. { array of char to string, the length check is done by the firstpass of this node }
  1303. if is_chararray(def_from) or
  1304. (is_equal(tarraydef(def_from).elementtype.def,cchartype.def) and
  1305. is_open_array(def_from)) then
  1306. begin
  1307. doconv:=tc_chararray_2_string;
  1308. if is_open_array(def_from) or
  1309. (is_shortstring(def_to) and
  1310. (def_from.size <= 255)) or
  1311. (is_ansistring(def_to) and
  1312. (def_from.size > 255)) then
  1313. b:=1
  1314. else
  1315. b:=2;
  1316. end;
  1317. end;
  1318. pointerdef :
  1319. begin
  1320. { pchar can be assigned to short/ansistrings,
  1321. but not in tp7 compatible mode }
  1322. if is_pchar(def_from) and not(m_tp7 in aktmodeswitches) then
  1323. begin
  1324. doconv:=tc_pchar_2_string;
  1325. { trefer ansistrings because pchars can overflow shortstrings, }
  1326. { but only if ansistrings are the default (JM) }
  1327. if (is_shortstring(def_to) and
  1328. not(cs_ansistrings in aktlocalswitches)) or
  1329. (is_ansistring(def_to) and
  1330. (cs_ansistrings in aktlocalswitches)) then
  1331. b:=1
  1332. else
  1333. b:=2;
  1334. end;
  1335. end;
  1336. end;
  1337. end;
  1338. floatdef :
  1339. begin
  1340. case def_from.deftype of
  1341. orddef :
  1342. begin { ordinal to real }
  1343. if is_integer(def_from) then
  1344. begin
  1345. doconv:=tc_int_2_real;
  1346. b:=1;
  1347. end;
  1348. end;
  1349. floatdef :
  1350. begin { 2 float types ? }
  1351. if tfloatdef(def_from).typ=tfloatdef(def_to).typ then
  1352. doconv:=tc_equal
  1353. else
  1354. doconv:=tc_real_2_real;
  1355. b:=1;
  1356. end;
  1357. end;
  1358. end;
  1359. enumdef :
  1360. begin
  1361. if (def_from.deftype=enumdef) then
  1362. begin
  1363. if explicit then
  1364. begin
  1365. b:=1;
  1366. doconv:=tc_int_2_int;
  1367. end
  1368. else
  1369. begin
  1370. hd1:=def_from;
  1371. while assigned(tenumdef(hd1).basedef) do
  1372. hd1:=tenumdef(hd1).basedef;
  1373. hd2:=def_to;
  1374. while assigned(tenumdef(hd2).basedef) do
  1375. hd2:=tenumdef(hd2).basedef;
  1376. if (hd1=hd2) then
  1377. begin
  1378. b:=1;
  1379. { because of packenum they can have different sizes! (JM) }
  1380. doconv:=tc_int_2_int;
  1381. end;
  1382. end;
  1383. end;
  1384. end;
  1385. arraydef :
  1386. begin
  1387. { open array is also compatible with a single element of its base type }
  1388. if is_open_array(def_to) and
  1389. is_equal(tarraydef(def_to).elementtype.def,def_from) then
  1390. begin
  1391. doconv:=tc_equal;
  1392. b:=1;
  1393. end
  1394. else
  1395. begin
  1396. case def_from.deftype of
  1397. arraydef :
  1398. begin
  1399. { array constructor -> open array }
  1400. if is_open_array(def_to) and
  1401. is_array_constructor(def_from) then
  1402. begin
  1403. if is_void(tarraydef(def_from).elementtype.def) or
  1404. is_equal(tarraydef(def_to).elementtype.def,tarraydef(def_from).elementtype.def) then
  1405. begin
  1406. doconv:=tc_equal;
  1407. b:=1;
  1408. end
  1409. else
  1410. if isconvertable(tarraydef(def_from).elementtype.def,
  1411. tarraydef(def_to).elementtype.def,hct,arrayconstructorn,false)<>0 then
  1412. begin
  1413. doconv:=hct;
  1414. b:=2;
  1415. end;
  1416. end
  1417. else
  1418. { dynamic array -> open array }
  1419. if is_dynamic_array(def_from) and
  1420. is_open_array(def_to) and
  1421. is_equal(tarraydef(def_to).elementtype.def,tarraydef(def_from).elementtype.def) then
  1422. begin
  1423. doconv := tc_dynarray_2_openarray;
  1424. b := 2;
  1425. end
  1426. else
  1427. { array of tvarrec -> array of const }
  1428. if is_array_of_const(def_to) and
  1429. is_equal(tarraydef(def_to).elementtype.def,tarraydef(def_from).elementtype.def) then
  1430. begin
  1431. doconv:=tc_equal;
  1432. b:=1;
  1433. end;
  1434. end;
  1435. pointerdef :
  1436. begin
  1437. if is_zero_based_array(def_to) and
  1438. is_equal(tpointerdef(def_from).pointertype.def,tarraydef(def_to).elementtype.def) then
  1439. begin
  1440. doconv:=tc_pointer_2_array;
  1441. b:=1;
  1442. end;
  1443. end;
  1444. stringdef :
  1445. begin
  1446. { string to char array }
  1447. if (not is_special_array(def_to)) and
  1448. is_char(tarraydef(def_to).elementtype.def) then
  1449. begin
  1450. doconv:=tc_string_2_chararray;
  1451. b:=1;
  1452. end;
  1453. end;
  1454. orddef:
  1455. begin
  1456. if is_chararray(def_to) and
  1457. is_char(def_from) then
  1458. begin
  1459. doconv:=tc_char_2_chararray;
  1460. b:=2;
  1461. end;
  1462. end;
  1463. recorddef :
  1464. begin
  1465. { tvarrec -> array of constconst }
  1466. if is_array_of_const(def_to) and
  1467. is_equal(def_from,tarraydef(def_to).elementtype.def) then
  1468. begin
  1469. doconv:=tc_equal;
  1470. b:=1;
  1471. end;
  1472. end;
  1473. end;
  1474. end;
  1475. end;
  1476. pointerdef :
  1477. begin
  1478. case def_from.deftype of
  1479. stringdef :
  1480. begin
  1481. { string constant (which can be part of array constructor)
  1482. to zero terminated string constant }
  1483. if (fromtreetype in [arrayconstructorn,stringconstn]) and
  1484. is_pchar(def_to) or is_pwidechar(def_to) then
  1485. begin
  1486. doconv:=tc_cstring_2_pchar;
  1487. b:=1;
  1488. end;
  1489. end;
  1490. orddef :
  1491. begin
  1492. { char constant to zero terminated string constant }
  1493. if (fromtreetype=ordconstn) then
  1494. begin
  1495. if is_equal(def_from,cchartype.def) and
  1496. is_pchar(def_to) then
  1497. begin
  1498. doconv:=tc_cchar_2_pchar;
  1499. b:=1;
  1500. end
  1501. else
  1502. if is_integer(def_from) then
  1503. begin
  1504. doconv:=tc_cord_2_pointer;
  1505. b:=1;
  1506. end;
  1507. end;
  1508. end;
  1509. arraydef :
  1510. begin
  1511. { chararray to pointer }
  1512. if is_zero_based_array(def_from) and
  1513. is_equal(tarraydef(def_from).elementtype.def,tpointerdef(def_to).pointertype.def) then
  1514. begin
  1515. doconv:=tc_array_2_pointer;
  1516. b:=1;
  1517. end;
  1518. end;
  1519. pointerdef :
  1520. begin
  1521. { child class pointer can be assigned to anchestor pointers }
  1522. if (
  1523. (tpointerdef(def_from).pointertype.def.deftype=objectdef) and
  1524. (tpointerdef(def_to).pointertype.def.deftype=objectdef) and
  1525. tobjectdef(tpointerdef(def_from).pointertype.def).is_related(
  1526. tobjectdef(tpointerdef(def_to).pointertype.def))
  1527. ) or
  1528. { all pointers can be assigned to void-pointer }
  1529. is_equal(tpointerdef(def_to).pointertype.def,voidtype.def) or
  1530. { in my opnion, is this not clean pascal }
  1531. { well, but it's handy to use, it isn't ? (FK) }
  1532. is_equal(tpointerdef(def_from).pointertype.def,voidtype.def) then
  1533. begin
  1534. { but don't allow conversion between farpointer-pointer }
  1535. if (tpointerdef(def_to).is_far=tpointerdef(def_from).is_far) then
  1536. begin
  1537. doconv:=tc_equal;
  1538. b:=1;
  1539. end;
  1540. end;
  1541. end;
  1542. procvardef :
  1543. begin
  1544. { procedure variable can be assigned to an void pointer }
  1545. { Not anymore. Use the @ operator now.}
  1546. if not(m_tp_procvar in aktmodeswitches) and
  1547. (tpointerdef(def_to).pointertype.def.deftype=orddef) and
  1548. (torddef(tpointerdef(def_to).pointertype.def).typ=uvoid) then
  1549. begin
  1550. doconv:=tc_equal;
  1551. b:=1;
  1552. end;
  1553. end;
  1554. classrefdef,
  1555. objectdef :
  1556. begin
  1557. { class types and class reference type
  1558. can be assigned to void pointers }
  1559. if (
  1560. is_class_or_interface(def_from) or
  1561. (def_from.deftype=classrefdef)
  1562. ) and
  1563. (tpointerdef(def_to).pointertype.def.deftype=orddef) and
  1564. (torddef(tpointerdef(def_to).pointertype.def).typ=uvoid) then
  1565. begin
  1566. doconv:=tc_equal;
  1567. b:=1;
  1568. end;
  1569. end;
  1570. end;
  1571. end;
  1572. setdef :
  1573. begin
  1574. { automatic arrayconstructor -> set conversion }
  1575. if is_array_constructor(def_from) then
  1576. begin
  1577. doconv:=tc_arrayconstructor_2_set;
  1578. b:=1;
  1579. end;
  1580. end;
  1581. procvardef :
  1582. begin
  1583. { proc -> procvar }
  1584. if (def_from.deftype=procdef) and
  1585. (m_tp_procvar in aktmodeswitches) then
  1586. begin
  1587. doconv:=tc_proc_2_procvar;
  1588. if proc_to_procvar_equal(tprocdef(def_from),tprocvardef(def_to),false) then
  1589. b:=1;
  1590. end
  1591. { procvar -> procvar }
  1592. else
  1593. if (def_from.deftype=procvardef) and
  1594. (proc_to_procvar_equal(tprocvardef(def_from),tprocvardef(def_to),false)) then
  1595. begin
  1596. doconv:=tc_equal;
  1597. b := 2;
  1598. end
  1599. else
  1600. { for example delphi allows the assignement from pointers }
  1601. { to procedure variables }
  1602. if (m_pointer_2_procedure in aktmodeswitches) and
  1603. (def_from.deftype=pointerdef) and
  1604. (tpointerdef(def_from).pointertype.def.deftype=orddef) and
  1605. (torddef(tpointerdef(def_from).pointertype.def).typ=uvoid) then
  1606. begin
  1607. doconv:=tc_equal;
  1608. b:=1;
  1609. end
  1610. else
  1611. { nil is compatible with procvars }
  1612. if (fromtreetype=niln) then
  1613. begin
  1614. doconv:=tc_equal;
  1615. b:=1;
  1616. end;
  1617. end;
  1618. objectdef :
  1619. begin
  1620. { object pascal objects }
  1621. if (def_from.deftype=objectdef) and
  1622. tobjectdef(def_from).is_related(tobjectdef(def_to)) then
  1623. begin
  1624. doconv:=tc_equal;
  1625. b:=1;
  1626. end
  1627. else
  1628. { Class/interface specific }
  1629. if is_class_or_interface(def_to) then
  1630. begin
  1631. { void pointer also for delphi mode }
  1632. if (m_delphi in aktmodeswitches) and
  1633. is_voidpointer(def_from) then
  1634. begin
  1635. doconv:=tc_equal;
  1636. b:=1;
  1637. end
  1638. else
  1639. { nil is compatible with class instances and interfaces }
  1640. if (fromtreetype=niln) then
  1641. begin
  1642. doconv:=tc_equal;
  1643. b:=1;
  1644. end
  1645. { classes can be assigned to interfaces }
  1646. else if is_interface(def_to) and
  1647. is_class(def_from) and
  1648. assigned(tobjectdef(def_from).implementedinterfaces) and
  1649. (tobjectdef(def_from).implementedinterfaces.searchintf(def_to)<>-1) then
  1650. begin
  1651. doconv:=tc_class_2_intf;
  1652. b:=1;
  1653. end
  1654. { Interface 2 GUID handling }
  1655. else if (def_to=tdef(rec_tguid)) and
  1656. (fromtreetype=typen) and
  1657. is_interface(def_from) and
  1658. tobjectdef(def_from).isiidguidvalid then
  1659. begin
  1660. b:=1;
  1661. doconv:=tc_equal;
  1662. end;
  1663. end;
  1664. end;
  1665. classrefdef :
  1666. begin
  1667. { class reference types }
  1668. if (def_from.deftype=classrefdef) then
  1669. begin
  1670. doconv:=tc_equal;
  1671. if tobjectdef(tclassrefdef(def_from).pointertype.def).is_related(
  1672. tobjectdef(tclassrefdef(def_to).pointertype.def)) then
  1673. b:=1;
  1674. end
  1675. else
  1676. { nil is compatible with class references }
  1677. if (fromtreetype=niln) then
  1678. begin
  1679. doconv:=tc_equal;
  1680. b:=1;
  1681. end;
  1682. end;
  1683. filedef :
  1684. begin
  1685. { typed files are all equal to the abstract file type
  1686. name TYPEDFILE in system.pp in is_equal in types.pas
  1687. the problem is that it sholud be also compatible to FILE
  1688. but this would leed to a problem for ASSIGN RESET and REWRITE
  1689. when trying to find the good overloaded function !!
  1690. so all file function are doubled in system.pp
  1691. this is not very beautiful !!}
  1692. if (def_from.deftype=filedef) and
  1693. (
  1694. (
  1695. (tfiledef(def_from).filetyp = ft_typed) and
  1696. (tfiledef(def_to).filetyp = ft_typed) and
  1697. (
  1698. (tfiledef(def_from).typedfiletype.def = tdef(voidtype.def)) or
  1699. (tfiledef(def_to).typedfiletype.def = tdef(voidtype.def))
  1700. )
  1701. ) or
  1702. (
  1703. (
  1704. (tfiledef(def_from).filetyp = ft_untyped) and
  1705. (tfiledef(def_to).filetyp = ft_typed)
  1706. ) or
  1707. (
  1708. (tfiledef(def_from).filetyp = ft_typed) and
  1709. (tfiledef(def_to).filetyp = ft_untyped)
  1710. )
  1711. )
  1712. ) then
  1713. begin
  1714. doconv:=tc_equal;
  1715. b:=1;
  1716. end
  1717. end;
  1718. recorddef :
  1719. begin
  1720. { interface -> guid }
  1721. if is_interface(def_from) and
  1722. (def_to=rec_tguid) then
  1723. begin
  1724. doconv:=tc_intf_2_guid;
  1725. b:=1;
  1726. end
  1727. else
  1728. begin
  1729. { assignment overwritten ?? }
  1730. if assignment_overloaded(def_from,def_to)<>nil then
  1731. b:=2;
  1732. end;
  1733. end;
  1734. else
  1735. begin
  1736. { assignment overwritten ?? }
  1737. if assignment_overloaded(def_from,def_to)<>nil then
  1738. b:=2;
  1739. end;
  1740. end;
  1741. isconvertable:=b;
  1742. end;
  1743. function CheckTypes(def1,def2 : tdef) : boolean;
  1744. var
  1745. s1,s2 : string;
  1746. begin
  1747. if not is_equal(def1,def2) then
  1748. begin
  1749. { Crash prevention }
  1750. if (not assigned(def1)) or (not assigned(def2)) then
  1751. Message(type_e_mismatch)
  1752. else
  1753. begin
  1754. s1:=def1.typename;
  1755. s2:=def2.typename;
  1756. if (s1<>'<unknown type>') and (s2<>'<unknown type>') then
  1757. Message2(type_e_not_equal_types,def1.typename,def2.typename)
  1758. else
  1759. Message(type_e_mismatch);
  1760. end;
  1761. CheckTypes:=false;
  1762. end
  1763. else
  1764. CheckTypes:=true;
  1765. end;
  1766. end.
  1767. {
  1768. $Log$
  1769. Revision 1.64 2002-01-24 18:25:53 peter
  1770. * implicit result variable generation for assembler routines
  1771. * removed m_tp modeswitch, use m_tp7 or not(m_fpc) instead
  1772. Revision 1.63 2002/01/24 12:33:53 jonas
  1773. * adapted ranges of native types to int64 (e.g. high cardinal is no
  1774. longer longint($ffffffff), but just $fffffff in psystem)
  1775. * small additional fix in 64bit rangecheck code generation for 32 bit
  1776. processors
  1777. * adaption of ranges required the matching talgorithm used for selecting
  1778. which overloaded procedure to call to be adapted. It should now always
  1779. select the closest match for ordinal parameters.
  1780. + inttostr(qword) in sysstr.inc/sysstrh.inc
  1781. + abs(int64), sqr(int64), sqr(qword) in systemh.inc/generic.inc (previous
  1782. fixes were required to be able to add them)
  1783. * is_in_limit() moved from ncal to types unit, should always be used
  1784. instead of direct comparisons of low/high values of orddefs because
  1785. qword is a special case
  1786. Revision 1.62 2002/01/06 21:50:44 peter
  1787. * proc_to_procvar_equal fixed for procvar-procvar
  1788. Revision 1.61 2002/01/06 12:08:16 peter
  1789. * removed uauto from orddef, use new range_to_basetype generating
  1790. the correct ordinal type for a range
  1791. Revision 1.60 2001/12/17 12:49:08 jonas
  1792. * added type conversion from procvar to procvar (if their arguments are
  1793. convertable, two procvars are convertable too) ("merged")
  1794. Revision 1.59 2001/12/10 14:34:04 jonas
  1795. * fixed type conversions from dynamic arrays to open arrays
  1796. Revision 1.58 2001/12/03 21:48:43 peter
  1797. * freemem change to value parameter
  1798. * torddef low/high range changed to int64
  1799. Revision 1.57 2001/11/14 01:12:45 florian
  1800. * variant paramter passing and functions results fixed
  1801. Revision 1.56 2001/11/02 23:24:12 jonas
  1802. * fixed web bug 1665 (allow char to chararray type conversion) ("merged")
  1803. Revision 1.55 2001/11/02 22:58:09 peter
  1804. * procsym definition rewrite
  1805. Revision 1.54 2001/10/28 17:22:25 peter
  1806. * allow assignment of overloaded procedures to procvars when we know
  1807. which procedure to take
  1808. Revision 1.52 2001/10/22 21:21:09 peter
  1809. * allow enum(enum)
  1810. Revision 1.51 2001/10/22 15:13:49 jonas
  1811. * allow typeconversion of open array-of-char to string
  1812. Revision 1.50 2001/10/20 19:28:39 peter
  1813. * interface 2 guid support
  1814. * guid constants support
  1815. Revision 1.49 2001/10/17 22:41:05 florian
  1816. * several widechar fixes, case works now
  1817. Revision 1.48 2001/10/16 17:15:44 jonas
  1818. * auto-converting from int64 to real is again allowed for all modes
  1819. (it's allowed in Delphi too)
  1820. Revision 1.47 2001/09/03 13:27:41 jonas
  1821. * compilerproc implementation of set addition/substraction/...
  1822. * changed the declaration of some set helpers somewhat to accomodate the
  1823. above change
  1824. * i386 still uses the old code for comparisons of sets, because its
  1825. helpers return the results in the flags
  1826. * dummy tc_normal_2_small_set type conversion because I need the original
  1827. resulttype of the set add nodes
  1828. NOTE: you have to start a cycle with 1.0.5!
  1829. Revision 1.46 2001/09/02 21:15:34 peter
  1830. * don't allow int64->real for delphi mode
  1831. Revision 1.45 2001/08/19 21:11:21 florian
  1832. * some bugs fix:
  1833. - overload; with external procedures fixed
  1834. - better selection of routine to do an overloaded
  1835. type case
  1836. - ... some more
  1837. Revision 1.44 2001/07/08 21:00:16 peter
  1838. * various widestring updates, it works now mostly without charset
  1839. mapping supported
  1840. Revision 1.43 2001/06/29 14:16:57 jonas
  1841. * fixed inconsistent handling of procvars in FPC mode (sometimes @ was
  1842. required to assign the address of a procedure to a procvar, sometimes
  1843. not. Now it is always required) (merged)
  1844. Revision 1.42 2001/05/08 21:06:33 florian
  1845. * some more support for widechars commited especially
  1846. regarding type casting and constants
  1847. Revision 1.41 2001/04/22 22:46:49 florian
  1848. * more variant support
  1849. Revision 1.40 2001/04/18 22:02:00 peter
  1850. * registration of targets and assemblers
  1851. Revision 1.39 2001/04/13 01:22:17 peter
  1852. * symtable change to classes
  1853. * range check generation and errors fixed, make cycle DEBUG=1 works
  1854. * memory leaks fixed
  1855. Revision 1.38 2001/04/04 21:30:47 florian
  1856. * applied several fixes to get the DD8 Delphi Unit compiled
  1857. e.g. "forward"-interfaces are working now
  1858. Revision 1.37 2001/04/02 21:20:35 peter
  1859. * resulttype rewrite
  1860. Revision 1.36 2001/03/23 00:16:07 florian
  1861. + some stuff to compile FreeCLX added
  1862. Revision 1.35 2001/03/03 12:38:33 jonas
  1863. + support for arraydefs in is_signed (for their rangetype, used in rangechecks)
  1864. Revision 1.34 2001/02/26 19:44:55 peter
  1865. * merged generic m68k updates from fixes branch
  1866. Revision 1.33 2001/02/26 12:47:46 jonas
  1867. * fixed bug in type checking for compatibility of set elements (merged)
  1868. * released fix in options.pas from Carl also for FPC (merged)
  1869. Revision 1.32 2001/02/20 21:44:25 peter
  1870. * tvarrec -> array of const fixed
  1871. Revision 1.31 2001/01/22 11:20:15 jonas
  1872. * fixed web bug 1363 (merged)
  1873. Revision 1.30 2001/01/08 21:43:38 peter
  1874. * string isn't compatible with array of char
  1875. Revision 1.29 2000/12/25 00:07:30 peter
  1876. + new tlinkedlist class (merge of old tstringqueue,tcontainer and
  1877. tlinkedlist objects)
  1878. Revision 1.28 2000/12/22 22:38:12 peter
  1879. * fixed bug #1286
  1880. Revision 1.27 2000/12/20 15:59:40 jonas
  1881. - removed obsolete special case for range checking of cardinal constants
  1882. at compile time
  1883. Revision 1.26 2000/12/11 19:13:54 jonas
  1884. * fixed range checking of cardinal constants
  1885. * fixed range checking of "qword constants" (they don't really exist,
  1886. but values > high(int64) were set to zero if assigned to qword)
  1887. Revision 1.25 2000/12/08 14:06:11 jonas
  1888. * fix for web bug 1245: arrays of char with size >255 are now passed to
  1889. overloaded procedures which expect ansistrings instead of shortstrings
  1890. if possible
  1891. * pointer to array of chars (when using $t+) are now also considered
  1892. pchars
  1893. Revision 1.24 2000/11/20 15:52:47 jonas
  1894. * testrange now always cuts a constant to the size of the destination
  1895. if a rangeerror occurred
  1896. * changed an "and $ffffffff" to "and (int64($fffffff) shl 4 + $f" to
  1897. work around the constant evaluation problem we currently have
  1898. Revision 1.23 2000/11/13 14:42:41 jonas
  1899. * fix in testrange so that 64bit constants are properly truncated when
  1900. assigned to 32bit vars
  1901. Revision 1.22 2000/11/13 11:30:55 florian
  1902. * some bugs with interfaces and NIL fixed
  1903. Revision 1.21 2000/11/12 23:24:12 florian
  1904. * interfaces are basically running
  1905. Revision 1.20 2000/11/11 16:13:31 peter
  1906. * farpointer and normal pointer aren't compatible
  1907. Revision 1.19 2000/11/06 22:30:30 peter
  1908. * more fixes
  1909. Revision 1.18 2000/11/04 14:25:22 florian
  1910. + merged Attila's changes for interfaces, not tested yet
  1911. Revision 1.17 2000/10/31 22:30:13 peter
  1912. * merged asm result patch part 2
  1913. Revision 1.16 2000/10/31 22:02:55 peter
  1914. * symtable splitted, no real code changes
  1915. Revision 1.15 2000/10/21 18:16:12 florian
  1916. * a lot of changes:
  1917. - basic dyn. array support
  1918. - basic C++ support
  1919. - some work for interfaces done
  1920. ....
  1921. Revision 1.14 2000/10/14 10:14:56 peter
  1922. * moehrendorf oct 2000 rewrite
  1923. Revision 1.13 2000/10/01 19:48:26 peter
  1924. * lot of compile updates for cg11
  1925. Revision 1.12 2000/09/30 16:08:46 peter
  1926. * more cg11 updates
  1927. Revision 1.11 2000/09/24 15:06:32 peter
  1928. * use defines.inc
  1929. Revision 1.10 2000/09/18 12:31:15 jonas
  1930. * fixed bug in push_addr_param for arrays (merged from fixes branch)
  1931. Revision 1.9 2000/09/10 20:16:21 peter
  1932. * array of const isn't equal with array of <type> (merged)
  1933. Revision 1.8 2000/08/19 19:51:03 peter
  1934. * fixed bug with comparing constsym strings
  1935. Revision 1.7 2000/08/16 13:06:07 florian
  1936. + support of 64 bit integer constants
  1937. Revision 1.6 2000/08/13 13:07:18 peter
  1938. * equal_paras now also checks default parameter value
  1939. Revision 1.5 2000/08/12 06:49:22 florian
  1940. + case statement for int64/qword implemented
  1941. Revision 1.4 2000/08/08 19:26:41 peter
  1942. * equal_constsym() needed for default para
  1943. Revision 1.3 2000/07/13 12:08:28 michael
  1944. + patched to 1.1.0 with former 1.09patch from peter
  1945. Revision 1.2 2000/07/13 11:32:53 michael
  1946. + removed logs
  1947. }