defbase.pas 75 KB

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