defbase.pas 75 KB

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