defbase.pas 72 KB

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