types.pas 79 KB

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