ncnv.pas 93 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722
  1. {
  2. $Id$
  3. Copyright (c) 2000-2002 by Florian Klaempfl
  4. Type checking and register allocation for type converting nodes
  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 ncnv;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. node,
  23. symtype,
  24. defutil,defcmp,
  25. nld
  26. {$ifdef Delphi}
  27. ,dmisc
  28. {$endif}
  29. ;
  30. type
  31. ttypeconvnode = class(tunarynode)
  32. totype : ttype;
  33. convtype : tconverttype;
  34. constructor create(node : tnode;const t : ttype);virtual;
  35. constructor create_explicit(node : tnode;const t : ttype);
  36. constructor ppuload(t:tnodetype;ppufile:tcompilerppufile);override;
  37. procedure ppuwrite(ppufile:tcompilerppufile);override;
  38. procedure buildderefimpl;override;
  39. procedure derefimpl;override;
  40. function getcopy : tnode;override;
  41. function pass_1 : tnode;override;
  42. function det_resulttype:tnode;override;
  43. procedure mark_write;override;
  44. function docompare(p: tnode) : boolean; override;
  45. procedure second_call_helper(c : tconverttype);
  46. private
  47. function resulttype_int_to_int : tnode;
  48. function resulttype_cord_to_pointer : tnode;
  49. function resulttype_chararray_to_string : tnode;
  50. function resulttype_string_to_chararray : tnode;
  51. function resulttype_string_to_string : tnode;
  52. function resulttype_char_to_string : tnode;
  53. function resulttype_char_to_chararray : tnode;
  54. function resulttype_int_to_real : tnode;
  55. function resulttype_real_to_real : tnode;
  56. function resulttype_real_to_currency : tnode;
  57. function resulttype_cchar_to_pchar : tnode;
  58. function resulttype_cstring_to_pchar : tnode;
  59. function resulttype_char_to_char : tnode;
  60. function resulttype_arrayconstructor_to_set : tnode;
  61. function resulttype_pchar_to_string : tnode;
  62. function resulttype_interface_to_guid : tnode;
  63. function resulttype_dynarray_to_openarray : tnode;
  64. function resulttype_pwchar_to_string : tnode;
  65. function resulttype_variant_to_dynarray : tnode;
  66. function resulttype_dynarray_to_variant : tnode;
  67. function resulttype_call_helper(c : tconverttype) : tnode;
  68. function resulttype_variant_to_enum : tnode;
  69. function resulttype_enum_to_variant : tnode;
  70. protected
  71. function first_int_to_int : tnode;virtual;
  72. function first_cstring_to_pchar : tnode;virtual;
  73. function first_string_to_chararray : tnode;virtual;
  74. function first_char_to_string : tnode;virtual;
  75. function first_nothing : tnode;virtual;
  76. function first_array_to_pointer : tnode;virtual;
  77. function first_int_to_real : tnode;virtual;
  78. function first_real_to_real : tnode;virtual;
  79. function first_pointer_to_array : tnode;virtual;
  80. function first_cchar_to_pchar : tnode;virtual;
  81. function first_bool_to_int : tnode;virtual;
  82. function first_int_to_bool : tnode;virtual;
  83. function first_bool_to_bool : tnode;virtual;
  84. function first_proc_to_procvar : tnode;virtual;
  85. function first_load_smallset : tnode;virtual;
  86. function first_cord_to_pointer : tnode;virtual;
  87. function first_ansistring_to_pchar : tnode;virtual;
  88. function first_arrayconstructor_to_set : tnode;virtual;
  89. function first_class_to_intf : tnode;virtual;
  90. function first_char_to_char : tnode;virtual;
  91. function first_call_helper(c : tconverttype) : tnode;
  92. { these wrapper are necessary, because the first_* stuff is called }
  93. { through a table. Without the wrappers override wouldn't have }
  94. { any effect }
  95. function _first_int_to_int : tnode;
  96. function _first_cstring_to_pchar : tnode;
  97. function _first_string_to_chararray : tnode;
  98. function _first_char_to_string : tnode;
  99. function _first_nothing : tnode;
  100. function _first_array_to_pointer : tnode;
  101. function _first_int_to_real : tnode;
  102. function _first_real_to_real: tnode;
  103. function _first_pointer_to_array : tnode;
  104. function _first_cchar_to_pchar : tnode;
  105. function _first_bool_to_int : tnode;
  106. function _first_int_to_bool : tnode;
  107. function _first_bool_to_bool : tnode;
  108. function _first_proc_to_procvar : tnode;
  109. function _first_load_smallset : tnode;
  110. function _first_cord_to_pointer : tnode;
  111. function _first_ansistring_to_pchar : tnode;
  112. function _first_arrayconstructor_to_set : tnode;
  113. function _first_class_to_intf : tnode;
  114. function _first_char_to_char : tnode;
  115. procedure _second_int_to_int;virtual;
  116. procedure _second_string_to_string;virtual;
  117. procedure _second_cstring_to_pchar;virtual;
  118. procedure _second_string_to_chararray;virtual;
  119. procedure _second_array_to_pointer;virtual;
  120. procedure _second_pointer_to_array;virtual;
  121. procedure _second_chararray_to_string;virtual;
  122. procedure _second_char_to_string;virtual;
  123. procedure _second_int_to_real;virtual;
  124. procedure _second_real_to_real;virtual;
  125. procedure _second_cord_to_pointer;virtual;
  126. procedure _second_proc_to_procvar;virtual;
  127. procedure _second_bool_to_int;virtual;
  128. procedure _second_int_to_bool;virtual;
  129. procedure _second_bool_to_bool;virtual;
  130. procedure _second_load_smallset;virtual;
  131. procedure _second_ansistring_to_pchar;virtual;
  132. procedure _second_class_to_intf;virtual;
  133. procedure _second_char_to_char;virtual;
  134. procedure _second_nothing; virtual;
  135. procedure second_int_to_int;virtual;abstract;
  136. procedure second_string_to_string;virtual;abstract;
  137. procedure second_cstring_to_pchar;virtual;abstract;
  138. procedure second_string_to_chararray;virtual;abstract;
  139. procedure second_array_to_pointer;virtual;abstract;
  140. procedure second_pointer_to_array;virtual;abstract;
  141. procedure second_chararray_to_string;virtual;abstract;
  142. procedure second_char_to_string;virtual;abstract;
  143. procedure second_int_to_real;virtual;abstract;
  144. procedure second_real_to_real;virtual;abstract;
  145. procedure second_cord_to_pointer;virtual;abstract;
  146. procedure second_proc_to_procvar;virtual;abstract;
  147. procedure second_bool_to_int;virtual;abstract;
  148. procedure second_int_to_bool;virtual;abstract;
  149. procedure second_bool_to_bool;virtual;abstract;
  150. procedure second_load_smallset;virtual;abstract;
  151. procedure second_ansistring_to_pchar;virtual;abstract;
  152. procedure second_class_to_intf;virtual;abstract;
  153. procedure second_char_to_char;virtual;abstract;
  154. procedure second_nothing; virtual;abstract;
  155. end;
  156. ttypeconvnodeclass = class of ttypeconvnode;
  157. tasnode = class(tbinarynode)
  158. constructor create(l,r : tnode);virtual;
  159. function pass_1 : tnode;override;
  160. function det_resulttype:tnode;override;
  161. function getcopy: tnode;override;
  162. destructor destroy; override;
  163. protected
  164. call: tnode;
  165. end;
  166. tasnodeclass = class of tasnode;
  167. tisnode = class(tbinarynode)
  168. constructor create(l,r : tnode);virtual;
  169. function pass_1 : tnode;override;
  170. function det_resulttype:tnode;override;
  171. procedure pass_2;override;
  172. end;
  173. tisnodeclass = class of tisnode;
  174. var
  175. ctypeconvnode : ttypeconvnodeclass;
  176. casnode : tasnodeclass;
  177. cisnode : tisnodeclass;
  178. procedure inserttypeconv(var p:tnode;const t:ttype);
  179. procedure inserttypeconv_explicit(var p:tnode;const t:ttype);
  180. procedure arrayconstructor_to_set(var p : tnode);
  181. implementation
  182. uses
  183. globtype,systems,tokens,
  184. cutils,verbose,globals,widestr,
  185. symconst,symdef,symsym,symtable,
  186. ncon,ncal,nset,nadd,ninl,nmem,nmat,
  187. cgbase,procinfo,
  188. htypechk,pass_1,cpuinfo;
  189. {*****************************************************************************
  190. Helpers
  191. *****************************************************************************}
  192. procedure inserttypeconv(var p:tnode;const t:ttype);
  193. begin
  194. if not assigned(p.resulttype.def) then
  195. begin
  196. resulttypepass(p);
  197. if codegenerror then
  198. exit;
  199. end;
  200. { don't insert obsolete type conversions }
  201. if equal_defs(p.resulttype.def,t.def) and
  202. not ((p.resulttype.def.deftype=setdef) and
  203. (tsetdef(p.resulttype.def).settype <>
  204. tsetdef(t.def).settype)) then
  205. begin
  206. p.resulttype:=t;
  207. end
  208. else
  209. begin
  210. p:=ctypeconvnode.create(p,t);
  211. resulttypepass(p);
  212. end;
  213. end;
  214. procedure inserttypeconv_explicit(var p:tnode;const t:ttype);
  215. begin
  216. if not assigned(p.resulttype.def) then
  217. begin
  218. resulttypepass(p);
  219. if codegenerror then
  220. exit;
  221. end;
  222. { don't insert obsolete type conversions }
  223. if equal_defs(p.resulttype.def,t.def) and
  224. not ((p.resulttype.def.deftype=setdef) and
  225. (tsetdef(p.resulttype.def).settype <>
  226. tsetdef(t.def).settype)) then
  227. begin
  228. p.resulttype:=t;
  229. end
  230. else
  231. begin
  232. p:=ctypeconvnode.create_explicit(p,t);
  233. resulttypepass(p);
  234. end;
  235. end;
  236. {*****************************************************************************
  237. Array constructor to Set Conversion
  238. *****************************************************************************}
  239. procedure arrayconstructor_to_set(var p : tnode);
  240. var
  241. constp : tsetconstnode;
  242. buildp,
  243. p2,p3,p4 : tnode;
  244. htype : ttype;
  245. constset : Pconstset;
  246. constsetlo,
  247. constsethi : TConstExprInt;
  248. procedure update_constsethi(t:ttype);
  249. begin
  250. if ((t.def.deftype=orddef) and
  251. (torddef(t.def).high>=constsethi)) then
  252. begin
  253. constsethi:=torddef(t.def).high;
  254. if htype.def=nil then
  255. begin
  256. if (constsethi>255) or
  257. (torddef(t.def).low<0) then
  258. htype:=u8inttype
  259. else
  260. htype:=t;
  261. end;
  262. if constsethi>255 then
  263. constsethi:=255;
  264. end
  265. else if ((t.def.deftype=enumdef) and
  266. (tenumdef(t.def).max>=constsethi)) then
  267. begin
  268. if htype.def=nil then
  269. htype:=t;
  270. constsethi:=tenumdef(t.def).max;
  271. end;
  272. end;
  273. procedure do_set(pos : longint);
  274. begin
  275. if (pos and not $ff)<>0 then
  276. Message(parser_e_illegal_set_expr);
  277. if pos>constsethi then
  278. constsethi:=pos;
  279. if pos<constsetlo then
  280. constsetlo:=pos;
  281. if pos in constset^ then
  282. Message(parser_e_illegal_set_expr);
  283. include(constset^,pos);
  284. end;
  285. var
  286. l : Longint;
  287. lr,hr : TConstExprInt;
  288. hp : tarrayconstructornode;
  289. begin
  290. if p.nodetype<>arrayconstructorn then
  291. internalerror(200205105);
  292. new(constset);
  293. constset^:=[];
  294. htype.reset;
  295. constsetlo:=0;
  296. constsethi:=0;
  297. constp:=csetconstnode.create(nil,htype);
  298. constp.value_set:=constset;
  299. buildp:=constp;
  300. hp:=tarrayconstructornode(p);
  301. if assigned(hp.left) then
  302. begin
  303. while assigned(hp) do
  304. begin
  305. p4:=nil; { will contain the tree to create the set }
  306. {split a range into p2 and p3 }
  307. if hp.left.nodetype=arrayconstructorrangen then
  308. begin
  309. p2:=tarrayconstructorrangenode(hp.left).left;
  310. p3:=tarrayconstructorrangenode(hp.left).right;
  311. tarrayconstructorrangenode(hp.left).left:=nil;
  312. tarrayconstructorrangenode(hp.left).right:=nil;
  313. end
  314. else
  315. begin
  316. p2:=hp.left;
  317. hp.left:=nil;
  318. p3:=nil;
  319. end;
  320. resulttypepass(p2);
  321. if assigned(p3) then
  322. resulttypepass(p3);
  323. if codegenerror then
  324. break;
  325. case p2.resulttype.def.deftype of
  326. enumdef,
  327. orddef:
  328. begin
  329. getrange(p2.resulttype.def,lr,hr);
  330. if assigned(p3) then
  331. begin
  332. { this isn't good, you'll get problems with
  333. type t010 = 0..10;
  334. ts = set of t010;
  335. var s : ts;b : t010
  336. begin s:=[1,2,b]; end.
  337. if is_integer(p3^.resulttype.def) then
  338. begin
  339. inserttypeconv(p3,u8bitdef);
  340. end;
  341. }
  342. if assigned(htype.def) and not(equal_defs(htype.def,p3.resulttype.def)) then
  343. begin
  344. aktfilepos:=p3.fileinfo;
  345. CGMessage(type_e_typeconflict_in_set);
  346. end
  347. else
  348. begin
  349. if (p2.nodetype=ordconstn) and (p3.nodetype=ordconstn) then
  350. begin
  351. if not(is_integer(p3.resulttype.def)) then
  352. htype:=p3.resulttype
  353. else
  354. begin
  355. inserttypeconv(p3,u8inttype);
  356. inserttypeconv(p2,u8inttype);
  357. end;
  358. for l:=tordconstnode(p2).value to tordconstnode(p3).value do
  359. do_set(l);
  360. p2.free;
  361. p3.free;
  362. end
  363. else
  364. begin
  365. update_constsethi(p2.resulttype);
  366. inserttypeconv(p2,htype);
  367. update_constsethi(p3.resulttype);
  368. inserttypeconv(p3,htype);
  369. if assigned(htype.def) then
  370. inserttypeconv(p3,htype)
  371. else
  372. inserttypeconv(p3,u8inttype);
  373. p4:=csetelementnode.create(p2,p3);
  374. end;
  375. end;
  376. end
  377. else
  378. begin
  379. { Single value }
  380. if p2.nodetype=ordconstn then
  381. begin
  382. if not(is_integer(p2.resulttype.def)) then
  383. update_constsethi(p2.resulttype)
  384. else
  385. inserttypeconv(p2,u8inttype);
  386. do_set(tordconstnode(p2).value);
  387. p2.free;
  388. end
  389. else
  390. begin
  391. update_constsethi(p2.resulttype);
  392. if assigned(htype.def) then
  393. inserttypeconv(p2,htype)
  394. else
  395. inserttypeconv(p2,u8inttype);
  396. p4:=csetelementnode.create(p2,nil);
  397. end;
  398. end;
  399. end;
  400. stringdef :
  401. begin
  402. { if we've already set elements which are constants }
  403. { throw an error }
  404. if ((htype.def=nil) and assigned(buildp)) or
  405. not(is_char(htype.def)) then
  406. CGMessage(type_e_typeconflict_in_set)
  407. else
  408. for l:=1 to length(pstring(tstringconstnode(p2).value_str)^) do
  409. do_set(ord(pstring(tstringconstnode(p2).value_str)^[l]));
  410. if htype.def=nil then
  411. htype:=cchartype;
  412. p2.free;
  413. end;
  414. else
  415. CGMessage(type_e_ordinal_expr_expected);
  416. end;
  417. { insert the set creation tree }
  418. if assigned(p4) then
  419. buildp:=caddnode.create(addn,buildp,p4);
  420. { load next and dispose current node }
  421. p2:=hp;
  422. hp:=tarrayconstructornode(tarrayconstructornode(p2).right);
  423. tarrayconstructornode(p2).right:=nil;
  424. p2.free;
  425. end;
  426. if (htype.def=nil) then
  427. htype:=u8inttype;
  428. end
  429. else
  430. begin
  431. { empty set [], only remove node }
  432. p.free;
  433. end;
  434. { set the initial set type }
  435. constp.resulttype.setdef(tsetdef.create(htype,constsethi));
  436. { determine the resulttype for the tree }
  437. resulttypepass(buildp);
  438. { set the new tree }
  439. p:=buildp;
  440. end;
  441. {*****************************************************************************
  442. TTYPECONVNODE
  443. *****************************************************************************}
  444. constructor ttypeconvnode.create(node : tnode;const t:ttype);
  445. begin
  446. inherited create(typeconvn,node);
  447. convtype:=tc_not_possible;
  448. totype:=t;
  449. if t.def=nil then
  450. internalerror(200103281);
  451. set_file_line(node);
  452. end;
  453. constructor ttypeconvnode.create_explicit(node : tnode;const t:ttype);
  454. begin
  455. self.create(node,t);
  456. include(flags,nf_explicit);
  457. end;
  458. constructor ttypeconvnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  459. begin
  460. inherited ppuload(t,ppufile);
  461. ppufile.gettype(totype);
  462. convtype:=tconverttype(ppufile.getbyte);
  463. end;
  464. procedure ttypeconvnode.ppuwrite(ppufile:tcompilerppufile);
  465. begin
  466. inherited ppuwrite(ppufile);
  467. ppufile.puttype(totype);
  468. ppufile.putbyte(byte(convtype));
  469. end;
  470. procedure ttypeconvnode.buildderefimpl;
  471. begin
  472. inherited buildderefimpl;
  473. totype.buildderef;
  474. end;
  475. procedure ttypeconvnode.derefimpl;
  476. begin
  477. inherited derefimpl;
  478. totype.resolve;
  479. end;
  480. function ttypeconvnode.getcopy : tnode;
  481. var
  482. n : ttypeconvnode;
  483. begin
  484. n:=ttypeconvnode(inherited getcopy);
  485. n.convtype:=convtype;
  486. getcopy:=n;
  487. end;
  488. function ttypeconvnode.resulttype_cord_to_pointer : tnode;
  489. var
  490. t : tnode;
  491. begin
  492. result:=nil;
  493. if left.nodetype=ordconstn then
  494. begin
  495. { check if we have a valid pointer constant (JM) }
  496. if (sizeof(pointer) > sizeof(TConstPtrUInt)) then
  497. if (sizeof(TConstPtrUInt) = 4) then
  498. begin
  499. if (tordconstnode(left).value < low(longint)) or
  500. (tordconstnode(left).value > high(cardinal)) then
  501. CGMessage(parser_e_range_check_error);
  502. end
  503. else if (sizeof(TConstPtrUInt) = 8) then
  504. begin
  505. if (tordconstnode(left).value < low(int64)) or
  506. (tordconstnode(left).value > high(qword)) then
  507. CGMessage(parser_e_range_check_error);
  508. end
  509. else
  510. internalerror(2001020801);
  511. t:=cpointerconstnode.create(TConstPtrUInt(tordconstnode(left).value),resulttype);
  512. result:=t;
  513. end
  514. else
  515. internalerror(200104023);
  516. end;
  517. function ttypeconvnode.resulttype_chararray_to_string : tnode;
  518. begin
  519. result := ccallnode.createinternres(
  520. 'fpc_chararray_to_'+tstringdef(resulttype.def).stringtypname,
  521. ccallparanode.create(left,nil),resulttype);
  522. left := nil;
  523. end;
  524. function ttypeconvnode.resulttype_string_to_chararray : tnode;
  525. var
  526. arrsize: longint;
  527. begin
  528. with tarraydef(resulttype.def) do
  529. begin
  530. if highrange<lowrange then
  531. internalerror(75432653);
  532. arrsize := highrange-lowrange+1;
  533. end;
  534. if (left.nodetype = stringconstn) and
  535. { left.length+1 since there's always a terminating #0 character (JM) }
  536. (tstringconstnode(left).len+1 >= arrsize) and
  537. (tstringdef(left.resulttype.def).string_typ=st_shortstring) then
  538. begin
  539. { handled separately }
  540. result := nil;
  541. exit;
  542. end;
  543. result := ccallnode.createinternres(
  544. 'fpc_'+tstringdef(left.resulttype.def).stringtypname+
  545. '_to_chararray',ccallparanode.create(left,ccallparanode.create(
  546. cordconstnode.create(arrsize,s32inttype,true),nil)),resulttype);
  547. left := nil;
  548. end;
  549. function ttypeconvnode.resulttype_string_to_string : tnode;
  550. var
  551. procname: string[31];
  552. stringpara : tcallparanode;
  553. pw : pcompilerwidestring;
  554. pc : pchar;
  555. begin
  556. result:=nil;
  557. if left.nodetype=stringconstn then
  558. begin
  559. { convert ascii 2 unicode }
  560. if (tstringdef(resulttype.def).string_typ=st_widestring) and
  561. (tstringconstnode(left).st_type in [st_ansistring,st_shortstring,st_longstring]) then
  562. begin
  563. initwidestring(pw);
  564. ascii2unicode(tstringconstnode(left).value_str,tstringconstnode(left).len,pw);
  565. ansistringdispose(tstringconstnode(left).value_str,tstringconstnode(left).len);
  566. pcompilerwidestring(tstringconstnode(left).value_str):=pw;
  567. end
  568. else
  569. { convert unicode 2 ascii }
  570. if (tstringconstnode(left).st_type=st_widestring) and
  571. (tstringdef(resulttype.def).string_typ in [st_ansistring,st_shortstring,st_longstring]) then
  572. begin
  573. pw:=pcompilerwidestring(tstringconstnode(left).value_str);
  574. getmem(pc,getlengthwidestring(pw)+1);
  575. unicode2ascii(pw,pc);
  576. donewidestring(pw);
  577. tstringconstnode(left).value_str:=pc;
  578. end;
  579. tstringconstnode(left).st_type:=tstringdef(resulttype.def).string_typ;
  580. tstringconstnode(left).resulttype:=resulttype;
  581. result:=left;
  582. left:=nil;
  583. end
  584. else
  585. begin
  586. { get the correct procedure name }
  587. procname := 'fpc_'+tstringdef(left.resulttype.def).stringtypname+
  588. '_to_'+tstringdef(resulttype.def).stringtypname;
  589. { create parameter (and remove left node from typeconvnode }
  590. { since it's reused as parameter) }
  591. stringpara := ccallparanode.create(left,nil);
  592. left := nil;
  593. { when converting to shortstrings, we have to pass high(destination) too }
  594. if (tstringdef(resulttype.def).string_typ = st_shortstring) then
  595. stringpara.right := ccallparanode.create(cinlinenode.create(
  596. in_high_x,false,self.getcopy),nil);
  597. { and create the callnode }
  598. result := ccallnode.createinternres(procname,stringpara,resulttype);
  599. end;
  600. end;
  601. function ttypeconvnode.resulttype_char_to_string : tnode;
  602. var
  603. procname: string[31];
  604. para : tcallparanode;
  605. hp : tstringconstnode;
  606. ws : pcompilerwidestring;
  607. begin
  608. result:=nil;
  609. if left.nodetype=ordconstn then
  610. begin
  611. if tstringdef(resulttype.def).string_typ=st_widestring then
  612. begin
  613. initwidestring(ws);
  614. concatwidestringchar(ws,tcompilerwidechar(chr(tordconstnode(left).value)));
  615. hp:=cstringconstnode.createwstr(ws);
  616. donewidestring(ws);
  617. end
  618. else
  619. hp:=cstringconstnode.createstr(chr(tordconstnode(left).value),tstringdef(resulttype.def).string_typ);
  620. result:=hp;
  621. end
  622. else
  623. { shortstrings are handled 'inline' }
  624. if tstringdef(resulttype.def).string_typ <> st_shortstring then
  625. begin
  626. { create the parameter }
  627. para := ccallparanode.create(left,nil);
  628. left := nil;
  629. { and the procname }
  630. procname := 'fpc_char_to_' +tstringdef(resulttype.def).stringtypname;
  631. { and finally the call }
  632. result := ccallnode.createinternres(procname,para,resulttype);
  633. end
  634. else
  635. begin
  636. { create word(byte(char) shl 8 or 1) for litte endian machines }
  637. { and word(byte(char) or 256) for big endian machines }
  638. left := ctypeconvnode.create_explicit(left,u8inttype);
  639. if (target_info.endian = endian_little) then
  640. left := caddnode.create(orn,
  641. cshlshrnode.create(shln,left,cordconstnode.create(8,s32inttype,false)),
  642. cordconstnode.create(1,s32inttype,false))
  643. else
  644. left := caddnode.create(orn,left,
  645. cordconstnode.create(1 shl 8,s32inttype,false));
  646. left := ctypeconvnode.create_explicit(left,u16inttype);
  647. resulttypepass(left);
  648. end;
  649. end;
  650. function ttypeconvnode.resulttype_char_to_chararray : tnode;
  651. begin
  652. if resulttype.def.size <> 1 then
  653. begin
  654. { convert first to string, then to chararray }
  655. inserttypeconv(left,cshortstringtype);
  656. inserttypeconv(left,resulttype);
  657. result:=left;
  658. left := nil;
  659. exit;
  660. end;
  661. result := nil;
  662. end;
  663. function ttypeconvnode.resulttype_char_to_char : tnode;
  664. var
  665. hp : tordconstnode;
  666. begin
  667. result:=nil;
  668. if left.nodetype=ordconstn then
  669. begin
  670. if (torddef(resulttype.def).typ=uchar) and
  671. (torddef(left.resulttype.def).typ=uwidechar) then
  672. begin
  673. hp:=cordconstnode.create(
  674. ord(unicode2asciichar(tcompilerwidechar(tordconstnode(left).value))),
  675. cchartype,true);
  676. result:=hp;
  677. end
  678. else if (torddef(resulttype.def).typ=uwidechar) and
  679. (torddef(left.resulttype.def).typ=uchar) then
  680. begin
  681. hp:=cordconstnode.create(
  682. asciichar2unicode(chr(tordconstnode(left).value)),
  683. cwidechartype,true);
  684. result:=hp;
  685. end
  686. else
  687. internalerror(200105131);
  688. exit;
  689. end;
  690. end;
  691. function ttypeconvnode.resulttype_int_to_int : tnode;
  692. var
  693. v : TConstExprInt;
  694. begin
  695. result:=nil;
  696. if left.nodetype=ordconstn then
  697. begin
  698. v:=tordconstnode(left).value;
  699. if is_currency(resulttype.def) then
  700. v:=v*10000;
  701. if (resulttype.def.deftype=pointerdef) then
  702. result:=cpointerconstnode.create(TConstPtrUInt(v),resulttype)
  703. else
  704. begin
  705. if is_currency(left.resulttype.def) then
  706. v:=v div 10000;
  707. result:=cordconstnode.create(v,resulttype,false);
  708. end;
  709. end
  710. else if left.nodetype=pointerconstn then
  711. begin
  712. v:=tpointerconstnode(left).value;
  713. if (resulttype.def.deftype=pointerdef) then
  714. result:=cpointerconstnode.create(v,resulttype)
  715. else
  716. begin
  717. if is_currency(resulttype.def) then
  718. v:=v*10000;
  719. result:=cordconstnode.create(v,resulttype,false);
  720. end;
  721. end
  722. else
  723. begin
  724. { multiply by 10000 for currency. We need to use getcopy to pass
  725. the argument because the current node is always disposed. Only
  726. inserting the multiply in the left node is not possible because
  727. it'll get in an infinite loop to convert int->currency }
  728. if is_currency(resulttype.def) then
  729. begin
  730. result:=caddnode.create(muln,getcopy,cordconstnode.create(10000,resulttype,false));
  731. include(result.flags,nf_is_currency);
  732. end
  733. else if is_currency(left.resulttype.def) then
  734. begin
  735. result:=cmoddivnode.create(divn,getcopy,cordconstnode.create(10000,resulttype,false));
  736. include(result.flags,nf_is_currency);
  737. end;
  738. end;
  739. end;
  740. function ttypeconvnode.resulttype_int_to_real : tnode;
  741. var
  742. rv : bestreal;
  743. begin
  744. result:=nil;
  745. if left.nodetype=ordconstn then
  746. begin
  747. rv:=tordconstnode(left).value;
  748. if is_currency(resulttype.def) then
  749. rv:=rv*10000.0
  750. else if is_currency(left.resulttype.def) then
  751. rv:=rv/10000.0;
  752. result:=crealconstnode.create(rv,resulttype);
  753. end
  754. else
  755. begin
  756. { multiply by 10000 for currency. We need to use getcopy to pass
  757. the argument because the current node is always disposed. Only
  758. inserting the multiply in the left node is not possible because
  759. it'll get in an infinite loop to convert int->currency }
  760. if is_currency(resulttype.def) then
  761. begin
  762. result:=caddnode.create(muln,getcopy,crealconstnode.create(10000.0,resulttype));
  763. include(result.flags,nf_is_currency);
  764. end
  765. else if is_currency(left.resulttype.def) then
  766. begin
  767. result:=caddnode.create(slashn,getcopy,crealconstnode.create(10000.0,resulttype));
  768. include(result.flags,nf_is_currency);
  769. end;
  770. end;
  771. end;
  772. function ttypeconvnode.resulttype_real_to_currency : tnode;
  773. begin
  774. if not is_currency(resulttype.def) then
  775. internalerror(200304221);
  776. result:=nil;
  777. left:=caddnode.create(muln,left,crealconstnode.create(10000.0,left.resulttype));
  778. include(left.flags,nf_is_currency);
  779. resulttypepass(left);
  780. { Convert constants directly, else call Round() }
  781. if left.nodetype=realconstn then
  782. result:=cordconstnode.create(round(trealconstnode(left).value_real),resulttype,false)
  783. else
  784. result:=ccallnode.createinternres('fpc_round',
  785. ccallparanode.create(left,nil),resulttype);
  786. left:=nil;
  787. end;
  788. function ttypeconvnode.resulttype_real_to_real : tnode;
  789. begin
  790. result:=nil;
  791. if is_currency(left.resulttype.def) and not(is_currency(resulttype.def)) then
  792. begin
  793. left:=caddnode.create(slashn,left,crealconstnode.create(10000.0,left.resulttype));
  794. include(left.flags,nf_is_currency);
  795. resulttypepass(left);
  796. end
  797. else
  798. if is_currency(resulttype.def) and not(is_currency(left.resulttype.def)) then
  799. begin
  800. left:=caddnode.create(muln,left,crealconstnode.create(10000.0,left.resulttype));
  801. include(left.flags,nf_is_currency);
  802. resulttypepass(left);
  803. end;
  804. if left.nodetype=realconstn then
  805. result:=crealconstnode.create(trealconstnode(left).value_real,resulttype);
  806. end;
  807. function ttypeconvnode.resulttype_cchar_to_pchar : tnode;
  808. begin
  809. result:=nil;
  810. if is_pwidechar(resulttype.def) then
  811. inserttypeconv(left,cwidestringtype)
  812. else
  813. inserttypeconv(left,cshortstringtype);
  814. { evaluate again, reset resulttype so the convert_typ
  815. will be calculated again and cstring_to_pchar will
  816. be used for futher conversion }
  817. result:=det_resulttype;
  818. end;
  819. function ttypeconvnode.resulttype_cstring_to_pchar : tnode;
  820. begin
  821. result:=nil;
  822. if is_pwidechar(resulttype.def) then
  823. inserttypeconv(left,cwidestringtype);
  824. end;
  825. function ttypeconvnode.resulttype_arrayconstructor_to_set : tnode;
  826. var
  827. hp : tnode;
  828. begin
  829. result:=nil;
  830. if left.nodetype<>arrayconstructorn then
  831. internalerror(5546);
  832. { remove typeconv node }
  833. hp:=left;
  834. left:=nil;
  835. { create a set constructor tree }
  836. arrayconstructor_to_set(hp);
  837. result:=hp;
  838. end;
  839. function ttypeconvnode.resulttype_pchar_to_string : tnode;
  840. begin
  841. result := ccallnode.createinternres(
  842. 'fpc_pchar_to_'+tstringdef(resulttype.def).stringtypname,
  843. ccallparanode.create(left,nil),resulttype);
  844. left := nil;
  845. end;
  846. function ttypeconvnode.resulttype_interface_to_guid : tnode;
  847. begin
  848. if assigned(tobjectdef(left.resulttype.def).iidguid) then
  849. result:=cguidconstnode.create(tobjectdef(left.resulttype.def).iidguid^);
  850. end;
  851. function ttypeconvnode.resulttype_dynarray_to_openarray : tnode;
  852. begin
  853. { a dynamic array is a pointer to an array, so to convert it to }
  854. { an open array, we have to dereference it (JM) }
  855. result := ctypeconvnode.create_explicit(left,voidpointertype);
  856. resulttypepass(result);
  857. { left is reused }
  858. left := nil;
  859. result := cderefnode.create(result);
  860. result.resulttype := resulttype;
  861. end;
  862. function ttypeconvnode.resulttype_pwchar_to_string : tnode;
  863. begin
  864. result := ccallnode.createinternres(
  865. 'fpc_pwidechar_to_'+tstringdef(resulttype.def).stringtypname,
  866. ccallparanode.create(left,nil),resulttype);
  867. left := nil;
  868. end;
  869. function ttypeconvnode.resulttype_variant_to_dynarray : tnode;
  870. begin
  871. result := ccallnode.createinternres(
  872. 'fpc_variant_to_dynarray',
  873. ccallparanode.create(caddrnode.create(crttinode.create(tstoreddef(resulttype.def),initrtti)),
  874. ccallparanode.create(left,nil)
  875. ),resulttype);
  876. left := nil;
  877. end;
  878. function ttypeconvnode.resulttype_dynarray_to_variant : tnode;
  879. begin
  880. result := ccallnode.createinternres(
  881. 'fpc_dynarray_to_variant',
  882. ccallparanode.create(caddrnode.create(crttinode.create(tstoreddef(resulttype.def),initrtti)),
  883. ccallparanode.create(left,nil)
  884. ),resulttype);
  885. result:=nil;
  886. end;
  887. function ttypeconvnode.resulttype_variant_to_enum : tnode;
  888. begin
  889. result := ctypeconvnode.create_explicit(left,sinttype);
  890. result := ctypeconvnode.create_explicit(result,resulttype);
  891. resulttypepass(result);
  892. { left is reused }
  893. left := nil;
  894. end;
  895. function ttypeconvnode.resulttype_enum_to_variant : tnode;
  896. begin
  897. result := ctypeconvnode.create_explicit(left,sinttype);
  898. result := ctypeconvnode.create_explicit(result,cvarianttype);
  899. resulttypepass(result);
  900. { left is reused }
  901. left := nil;
  902. end;
  903. function ttypeconvnode.resulttype_call_helper(c : tconverttype) : tnode;
  904. {$ifdef fpc}
  905. const
  906. resulttypeconvert : array[tconverttype] of pointer = (
  907. {equal} nil,
  908. {not_possible} nil,
  909. { string_2_string } @ttypeconvnode.resulttype_string_to_string,
  910. { char_2_string } @ttypeconvnode.resulttype_char_to_string,
  911. { char_2_chararray } @ttypeconvnode.resulttype_char_to_chararray,
  912. { pchar_2_string } @ttypeconvnode.resulttype_pchar_to_string,
  913. { cchar_2_pchar } @ttypeconvnode.resulttype_cchar_to_pchar,
  914. { cstring_2_pchar } @ttypeconvnode.resulttype_cstring_to_pchar,
  915. { ansistring_2_pchar } nil,
  916. { string_2_chararray } @ttypeconvnode.resulttype_string_to_chararray,
  917. { chararray_2_string } @ttypeconvnode.resulttype_chararray_to_string,
  918. { array_2_pointer } nil,
  919. { pointer_2_array } nil,
  920. { int_2_int } @ttypeconvnode.resulttype_int_to_int,
  921. { int_2_bool } nil,
  922. { bool_2_bool } nil,
  923. { bool_2_int } nil,
  924. { real_2_real } @ttypeconvnode.resulttype_real_to_real,
  925. { int_2_real } @ttypeconvnode.resulttype_int_to_real,
  926. { real_2_currency } @ttypeconvnode.resulttype_real_to_currency,
  927. { proc_2_procvar } nil,
  928. { arrayconstructor_2_set } @ttypeconvnode.resulttype_arrayconstructor_to_set,
  929. { load_smallset } nil,
  930. { cord_2_pointer } @ttypeconvnode.resulttype_cord_to_pointer,
  931. { intf_2_string } nil,
  932. { intf_2_guid } @ttypeconvnode.resulttype_interface_to_guid,
  933. { class_2_intf } nil,
  934. { char_2_char } @ttypeconvnode.resulttype_char_to_char,
  935. { normal_2_smallset} nil,
  936. { dynarray_2_openarray} @resulttype_dynarray_to_openarray,
  937. { pwchar_2_string} @resulttype_pwchar_to_string,
  938. { variant_2_dynarray} @resulttype_variant_to_dynarray,
  939. { dynarray_2_variant} @resulttype_dynarray_to_variant,
  940. { variant_2_enum} @resulttype_variant_to_enum,
  941. { enum_2_variant} @resulttype_enum_to_variant
  942. );
  943. type
  944. tprocedureofobject = function : tnode of object;
  945. var
  946. r : packed record
  947. proc : pointer;
  948. obj : pointer;
  949. end;
  950. begin
  951. result:=nil;
  952. { this is a little bit dirty but it works }
  953. { and should be quite portable too }
  954. r.proc:=resulttypeconvert[c];
  955. r.obj:=self;
  956. if assigned(r.proc) then
  957. result:=tprocedureofobject(r)();
  958. end;
  959. {$else}
  960. begin
  961. case c of
  962. tc_string_2_string: resulttype_string_to_string;
  963. tc_char_2_string : resulttype_char_to_string;
  964. tc_char_2_chararray: resulttype_char_to_chararray;
  965. tc_pchar_2_string : resulttype_pchar_to_string;
  966. tc_cchar_2_pchar : resulttype_cchar_to_pchar;
  967. tc_cstring_2_pchar : resulttype_cstring_to_pchar;
  968. tc_string_2_chararray : resulttype_string_to_chararray;
  969. tc_chararray_2_string : resulttype_chararray_to_string;
  970. tc_real_2_real : resulttype_real_to_real;
  971. tc_int_2_real : resulttype_int_to_real;
  972. tc_real_2_currency : resulttype_real_to_currency;
  973. tc_arrayconstructor_2_set : resulttype_arrayconstructor_to_set;
  974. tc_cord_2_pointer : resulttype_cord_to_pointer;
  975. tc_intf_2_guid : resulttype_interface_to_guid;
  976. tc_char_2_char : resulttype_char_to_char;
  977. tc_dynarray_2_openarray : resulttype_dynarray_to_openarray;
  978. tc_pwchar_2_string : resulttype_pwchar_to_string;
  979. tc_variant_2_dynarray : resulttype_variant_to_dynarray;
  980. tc_dynarray_2_variant : resulttype_dynarray_to_variant;
  981. end;
  982. end;
  983. {$Endif fpc}
  984. function ttypeconvnode.det_resulttype:tnode;
  985. var
  986. hp : tnode;
  987. currprocdef,
  988. aprocdef : tprocdef;
  989. eq : tequaltype;
  990. cdoptions : tcompare_defs_options;
  991. begin
  992. result:=nil;
  993. resulttype:=totype;
  994. resulttypepass(left);
  995. if codegenerror then
  996. exit;
  997. { When absolute force tc_equal }
  998. if (nf_absolute in flags) then
  999. begin
  1000. convtype:=tc_equal;
  1001. exit;
  1002. end;
  1003. cdoptions:=[cdo_check_operator,cdo_allow_variant];
  1004. if nf_explicit in flags then
  1005. include(cdoptions,cdo_explicit);
  1006. eq:=compare_defs_ext(left.resulttype.def,resulttype.def,left.nodetype,convtype,aprocdef,cdoptions);
  1007. case eq of
  1008. te_exact,
  1009. te_equal :
  1010. begin
  1011. { because is_equal only checks the basetype for sets we need to
  1012. check here if we are loading a smallset into a normalset }
  1013. if (resulttype.def.deftype=setdef) and
  1014. (left.resulttype.def.deftype=setdef) and
  1015. ((tsetdef(resulttype.def).settype = smallset) xor
  1016. (tsetdef(left.resulttype.def).settype = smallset)) then
  1017. begin
  1018. { constant sets can be converted by changing the type only }
  1019. if (left.nodetype=setconstn) then
  1020. begin
  1021. left.resulttype:=resulttype;
  1022. result:=left;
  1023. left:=nil;
  1024. exit;
  1025. end;
  1026. if (tsetdef(resulttype.def).settype <> smallset) then
  1027. convtype:=tc_load_smallset
  1028. else
  1029. convtype := tc_normal_2_smallset;
  1030. exit;
  1031. end
  1032. else
  1033. begin
  1034. { Only leave when there is no conversion to do.
  1035. We can still need to call a conversion routine,
  1036. like the routine to convert a stringconstnode }
  1037. if convtype in [tc_equal,tc_not_possible] then
  1038. begin
  1039. left.resulttype:=resulttype;
  1040. result:=left;
  1041. left:=nil;
  1042. exit;
  1043. end;
  1044. end;
  1045. end;
  1046. te_convert_l1,
  1047. te_convert_l2,
  1048. te_convert_l3 :
  1049. begin
  1050. { nothing to do }
  1051. end;
  1052. te_convert_operator :
  1053. begin
  1054. include(current_procinfo.flags,pi_do_call);
  1055. inc(aprocdef.procsym.refs);
  1056. hp:=ccallnode.create(ccallparanode.create(left,nil),
  1057. Tprocsym(aprocdef.procsym),nil,nil);
  1058. { tell explicitly which def we must use !! (PM) }
  1059. tcallnode(hp).procdefinition:=aprocdef;
  1060. left:=nil;
  1061. result:=hp;
  1062. exit;
  1063. end;
  1064. te_incompatible :
  1065. begin
  1066. { Procedures have a resulttype.def of voiddef and functions of their
  1067. own resulttype.def. They will therefore always be incompatible with
  1068. a procvar. Because isconvertable cannot check for procedures we
  1069. use an extra check for them.}
  1070. if (m_tp_procvar in aktmodeswitches) and
  1071. (resulttype.def.deftype=procvardef) then
  1072. begin
  1073. if is_procsym_load(left) then
  1074. begin
  1075. if (left.nodetype<>addrn) then
  1076. begin
  1077. convtype:=tc_proc_2_procvar;
  1078. { Now check if the procedure we are going to assign to
  1079. the procvar, is compatible with the procvar's type }
  1080. if not(nf_explicit in flags) and
  1081. (proc_to_procvar_equal(tprocsym(tloadnode(left).symtableentry).first_procdef,
  1082. tprocvardef(resulttype.def),true)=te_incompatible) then
  1083. IncompatibleTypes(tprocsym(tloadnode(left).symtableentry).first_procdef,resulttype.def);
  1084. exit;
  1085. end;
  1086. end
  1087. else
  1088. if (left.nodetype=calln) and
  1089. (tcallnode(left).para_count=0) then
  1090. begin
  1091. if assigned(tcallnode(left).right) then
  1092. begin
  1093. { this is already a procvar, if it is really equal
  1094. is checked below }
  1095. convtype:=tc_equal;
  1096. hp:=tcallnode(left).right.getcopy;
  1097. currprocdef:=tprocdef(hp.resulttype.def);
  1098. end
  1099. else
  1100. begin
  1101. convtype:=tc_proc_2_procvar;
  1102. currprocdef:=Tprocsym(Tcallnode(left).symtableprocentry).search_procdef_byprocvardef(Tprocvardef(resulttype.def));
  1103. hp:=cloadnode.create_procvar(tprocsym(tcallnode(left).symtableprocentry),
  1104. currprocdef,tcallnode(left).symtableproc);
  1105. if (tcallnode(left).symtableprocentry.owner.symtabletype=objectsymtable) then
  1106. begin
  1107. if assigned(tcallnode(left).methodpointer) then
  1108. begin
  1109. { Under certain circumstances the methodpointer is a loadvmtaddrn
  1110. which isn't possible if it is used as a method pointer, so
  1111. fix this.
  1112. If you change this, ensure that tests/tbs/tw2669.pp still works }
  1113. if tcallnode(left).methodpointer.nodetype=loadvmtaddrn then
  1114. tloadnode(hp).set_mp(tloadvmtaddrnode(tcallnode(left).methodpointer).left.getcopy)
  1115. else
  1116. tloadnode(hp).set_mp(tcallnode(left).methodpointer.getcopy);
  1117. end
  1118. else
  1119. tloadnode(hp).set_mp(load_self_node);
  1120. end;
  1121. resulttypepass(hp);
  1122. end;
  1123. left.free;
  1124. left:=hp;
  1125. { Now check if the procedure we are going to assign to
  1126. the procvar, is compatible with the procvar's type }
  1127. if not(nf_explicit in flags) and
  1128. (proc_to_procvar_equal(currprocdef,
  1129. tprocvardef(resulttype.def),true)=te_incompatible) then
  1130. IncompatibleTypes(left.resulttype.def,resulttype.def);
  1131. exit;
  1132. end;
  1133. end;
  1134. { Handle explicit type conversions }
  1135. if nf_explicit in flags then
  1136. begin
  1137. { do common tc_equal cast }
  1138. convtype:=tc_equal;
  1139. { check if the result could be in a register }
  1140. if (not(tstoreddef(resulttype.def).is_intregable) and
  1141. not(tstoreddef(resulttype.def).is_fpuregable)) or
  1142. ((left.resulttype.def.deftype = floatdef) and
  1143. (resulttype.def.deftype <> floatdef)) then
  1144. make_not_regable(left);
  1145. { class to class or object to object, with checkobject support }
  1146. if (resulttype.def.deftype=objectdef) and
  1147. (left.resulttype.def.deftype=objectdef) then
  1148. begin
  1149. if (cs_check_object in aktlocalswitches) then
  1150. begin
  1151. if is_class_or_interface(resulttype.def) then
  1152. begin
  1153. { we can translate the typeconvnode to 'as' when
  1154. typecasting to a class or interface }
  1155. hp:=casnode.create(left,cloadvmtaddrnode.create(ctypenode.create(resulttype)));
  1156. left:=nil;
  1157. result:=hp;
  1158. exit;
  1159. end;
  1160. end
  1161. else
  1162. begin
  1163. { check if the types are related }
  1164. if (not(tobjectdef(left.resulttype.def).is_related(tobjectdef(resulttype.def)))) and
  1165. (not(tobjectdef(resulttype.def).is_related(tobjectdef(left.resulttype.def)))) then
  1166. CGMessage2(type_w_classes_not_related,left.resulttype.def.typename,resulttype.def.typename);
  1167. end;
  1168. end
  1169. else
  1170. begin
  1171. { only if the same size or formal def }
  1172. if not(
  1173. (left.resulttype.def.deftype=formaldef) or
  1174. (
  1175. not(is_open_array(left.resulttype.def)) and
  1176. (left.resulttype.def.size=resulttype.def.size)
  1177. ) or
  1178. (
  1179. is_void(left.resulttype.def) and
  1180. (left.nodetype=derefn)
  1181. )
  1182. ) then
  1183. CGMessage(cg_e_illegal_type_conversion);
  1184. end;
  1185. end
  1186. else
  1187. IncompatibleTypes(left.resulttype.def,resulttype.def);
  1188. end;
  1189. else
  1190. internalerror(200211231);
  1191. end;
  1192. { Give hint for unportable code }
  1193. if ((left.resulttype.def.deftype=orddef) and
  1194. (resulttype.def.deftype in [pointerdef,procvardef,classrefdef])) or
  1195. ((resulttype.def.deftype=orddef) and
  1196. (left.resulttype.def.deftype in [pointerdef,procvardef,classrefdef])) then
  1197. CGMessage(cg_h_pointer_to_longint_conv_not_portable);
  1198. { Constant folding and other node transitions to
  1199. remove the typeconv node }
  1200. case left.nodetype of
  1201. loadn :
  1202. begin
  1203. { tp7 procvar support, when right is not a procvardef and we got a
  1204. loadn of a procvar (ignore procedures as void can not be converted)
  1205. then convert to a calln, the check for the result is already done
  1206. in is_convertible, also no conflict with @procvar is here because
  1207. that has an extra addrn.
  1208. The following deftypes always access the procvar: recorddef,setdef. This
  1209. has been tested with Kylix using trial and error }
  1210. if (m_tp_procvar in aktmodeswitches) and
  1211. (resulttype.def.deftype<>procvardef) and
  1212. { ignore internal typecasts to access methodpointer fields }
  1213. not(resulttype.def.deftype in [recorddef,setdef]) and
  1214. (left.resulttype.def.deftype=procvardef) and
  1215. (not is_void(tprocvardef(left.resulttype.def).rettype.def)) then
  1216. begin
  1217. hp:=ccallnode.create_procvar(nil,left);
  1218. resulttypepass(hp);
  1219. left:=hp;
  1220. end;
  1221. end;
  1222. calln :
  1223. begin
  1224. { See remark for loadn, this is the reverse }
  1225. if (m_tp_procvar in aktmodeswitches) and
  1226. (resulttype.def.deftype in [recorddef,setdef]) and
  1227. assigned(tcallnode(left).right) and
  1228. (tcallnode(left).para_count=0) then
  1229. begin
  1230. hp:=tcallnode(left).right.getcopy;
  1231. resulttypepass(hp);
  1232. left.free;
  1233. left:=hp;
  1234. end;
  1235. end;
  1236. niln :
  1237. begin
  1238. { nil to ordinal node }
  1239. if (resulttype.def.deftype=orddef) then
  1240. begin
  1241. hp:=cordconstnode.create(0,resulttype,true);
  1242. result:=hp;
  1243. exit;
  1244. end
  1245. else
  1246. { fold nil to any pointer type }
  1247. if (resulttype.def.deftype=pointerdef) then
  1248. begin
  1249. hp:=cnilnode.create;
  1250. hp.resulttype:=resulttype;
  1251. result:=hp;
  1252. exit;
  1253. end
  1254. else
  1255. { remove typeconv after niln, but not when the result is a
  1256. methodpointer. The typeconv of the methodpointer will then
  1257. take care of updateing size of niln to OS_64 }
  1258. if not((resulttype.def.deftype=procvardef) and
  1259. (po_methodpointer in tprocvardef(resulttype.def).procoptions)) then
  1260. begin
  1261. left.resulttype:=resulttype;
  1262. result:=left;
  1263. left:=nil;
  1264. exit;
  1265. end;
  1266. end;
  1267. ordconstn :
  1268. begin
  1269. { ordinal contants can be directly converted }
  1270. { but not char to char because it is a widechar to char or via versa }
  1271. { which needs extra code to do the code page transistion }
  1272. if is_ordinal(resulttype.def) and
  1273. not(convtype=tc_char_2_char) then
  1274. begin
  1275. { replace the resulttype and recheck the range }
  1276. left.resulttype:=resulttype;
  1277. testrange(left.resulttype.def,tordconstnode(left).value,(nf_explicit in flags));
  1278. result:=left;
  1279. left:=nil;
  1280. exit;
  1281. end;
  1282. end;
  1283. pointerconstn :
  1284. begin
  1285. { pointerconstn to any pointer is folded too }
  1286. if (resulttype.def.deftype=pointerdef) then
  1287. begin
  1288. left.resulttype:=resulttype;
  1289. result:=left;
  1290. left:=nil;
  1291. exit;
  1292. end
  1293. { constant pointer to ordinal }
  1294. else if is_ordinal(resulttype.def) then
  1295. begin
  1296. hp:=cordconstnode.create(tpointerconstnode(left).value,
  1297. resulttype,true);
  1298. result:=hp;
  1299. exit;
  1300. end;
  1301. end;
  1302. end;
  1303. { now call the resulttype helper to do constant folding }
  1304. result:=resulttype_call_helper(convtype);
  1305. end;
  1306. procedure Ttypeconvnode.mark_write;
  1307. begin
  1308. left.mark_write;
  1309. end;
  1310. function ttypeconvnode.first_cord_to_pointer : tnode;
  1311. begin
  1312. result:=nil;
  1313. internalerror(200104043);
  1314. end;
  1315. function ttypeconvnode.first_int_to_int : tnode;
  1316. begin
  1317. first_int_to_int:=nil;
  1318. if (left.expectloc<>LOC_REGISTER) and
  1319. not is_void(left.resulttype.def) and
  1320. (resulttype.def.size>left.resulttype.def.size) then
  1321. expectloc:=LOC_REGISTER
  1322. else
  1323. expectloc:=left.expectloc;
  1324. {$ifndef cpu64bit}
  1325. if is_64bit(resulttype.def) then
  1326. registersint:=max(registersint,2)
  1327. else
  1328. {$endif cpu64bit}
  1329. registersint:=max(registersint,1);
  1330. end;
  1331. function ttypeconvnode.first_cstring_to_pchar : tnode;
  1332. begin
  1333. first_cstring_to_pchar:=nil;
  1334. registersint:=1;
  1335. expectloc:=LOC_REGISTER;
  1336. end;
  1337. function ttypeconvnode.first_string_to_chararray : tnode;
  1338. begin
  1339. first_string_to_chararray:=nil;
  1340. expectloc:=left.expectloc;
  1341. end;
  1342. function ttypeconvnode.first_char_to_string : tnode;
  1343. begin
  1344. first_char_to_string:=nil;
  1345. expectloc:=LOC_REFERENCE;
  1346. end;
  1347. function ttypeconvnode.first_nothing : tnode;
  1348. begin
  1349. first_nothing:=nil;
  1350. end;
  1351. function ttypeconvnode.first_array_to_pointer : tnode;
  1352. begin
  1353. first_array_to_pointer:=nil;
  1354. if registersint<1 then
  1355. registersint:=1;
  1356. expectloc:=LOC_REGISTER;
  1357. end;
  1358. function ttypeconvnode.first_int_to_real: tnode;
  1359. var
  1360. fname: string[32];
  1361. typname : string[12];
  1362. begin
  1363. { Get the type name }
  1364. { Normally the typename should be one of the following:
  1365. single, double - carl
  1366. }
  1367. typname := lower(pbestrealtype^.def.gettypename);
  1368. { converting a 64bit integer to a float requires a helper }
  1369. if is_64bit(left.resulttype.def) then
  1370. begin
  1371. if is_signed(left.resulttype.def) then
  1372. fname := 'fpc_int64_to_'+typname
  1373. else
  1374. {$warning generic conversion from int to float does not support unsigned integers}
  1375. fname := 'fpc_int64_to_'+typname;
  1376. result := ccallnode.createintern(fname,ccallparanode.create(
  1377. left,nil));
  1378. left:=nil;
  1379. firstpass(result);
  1380. exit;
  1381. end
  1382. else
  1383. { other integers are supposed to be 32 bit }
  1384. begin
  1385. {$warning generic conversion from int to float does not support unsigned integers}
  1386. if is_signed(left.resulttype.def) then
  1387. fname := 'fpc_longint_to_'+typname
  1388. else
  1389. fname := 'fpc_longint_to_'+typname;
  1390. result := ccallnode.createintern(fname,ccallparanode.create(
  1391. left,nil));
  1392. left:=nil;
  1393. firstpass(result);
  1394. exit;
  1395. end;
  1396. end;
  1397. function ttypeconvnode.first_real_to_real : tnode;
  1398. begin
  1399. first_real_to_real:=nil;
  1400. { comp isn't a floating type }
  1401. if registersfpu<1 then
  1402. registersfpu:=1;
  1403. expectloc:=LOC_FPUREGISTER;
  1404. end;
  1405. function ttypeconvnode.first_pointer_to_array : tnode;
  1406. begin
  1407. first_pointer_to_array:=nil;
  1408. if registersint<1 then
  1409. registersint:=1;
  1410. expectloc:=LOC_REFERENCE;
  1411. end;
  1412. function ttypeconvnode.first_cchar_to_pchar : tnode;
  1413. begin
  1414. first_cchar_to_pchar:=nil;
  1415. internalerror(200104021);
  1416. end;
  1417. function ttypeconvnode.first_bool_to_int : tnode;
  1418. begin
  1419. first_bool_to_int:=nil;
  1420. { byte(boolean) or word(wordbool) or longint(longbool) must
  1421. be accepted for var parameters }
  1422. if (nf_explicit in flags) and
  1423. (left.resulttype.def.size=resulttype.def.size) and
  1424. (left.expectloc in [LOC_REFERENCE,LOC_CREFERENCE,LOC_CREGISTER]) then
  1425. exit;
  1426. { when converting to 64bit, first convert to a 32bit int and then }
  1427. { convert to a 64bit int (only necessary for 32bit processors) (JM) }
  1428. if resulttype.def.size > sizeof(aword) then
  1429. begin
  1430. result := ctypeconvnode.create_explicit(left,u32inttype);
  1431. result := ctypeconvnode.create(result,resulttype);
  1432. left := nil;
  1433. firstpass(result);
  1434. exit;
  1435. end;
  1436. expectloc:=LOC_REGISTER;
  1437. if registersint<1 then
  1438. registersint:=1;
  1439. end;
  1440. function ttypeconvnode.first_int_to_bool : tnode;
  1441. begin
  1442. first_int_to_bool:=nil;
  1443. { byte(boolean) or word(wordbool) or longint(longbool) must
  1444. be accepted for var parameters }
  1445. if (nf_explicit in flags) and
  1446. (left.resulttype.def.size=resulttype.def.size) and
  1447. (left.expectloc in [LOC_REFERENCE,LOC_CREFERENCE,LOC_CREGISTER]) then
  1448. exit;
  1449. expectloc:=LOC_REGISTER;
  1450. { need if bool to bool !!
  1451. not very nice !!
  1452. insertypeconv(left,s32inttype);
  1453. left.explizit:=true;
  1454. firstpass(left); }
  1455. if registersint<1 then
  1456. registersint:=1;
  1457. end;
  1458. function ttypeconvnode.first_bool_to_bool : tnode;
  1459. begin
  1460. first_bool_to_bool:=nil;
  1461. expectloc:=LOC_REGISTER;
  1462. if registersint<1 then
  1463. registersint:=1;
  1464. end;
  1465. function ttypeconvnode.first_char_to_char : tnode;
  1466. begin
  1467. first_char_to_char:=first_int_to_int;
  1468. end;
  1469. function ttypeconvnode.first_proc_to_procvar : tnode;
  1470. begin
  1471. first_proc_to_procvar:=nil;
  1472. if assigned(tunarynode(left).left) then
  1473. begin
  1474. if (left.expectloc<>LOC_CREFERENCE) then
  1475. CGMessage(cg_e_illegal_expression);
  1476. registersint:=left.registersint;
  1477. expectloc:=left.expectloc
  1478. end
  1479. else
  1480. begin
  1481. registersint:=left.registersint;
  1482. if registersint<1 then
  1483. registersint:=1;
  1484. expectloc:=LOC_REGISTER;
  1485. end
  1486. end;
  1487. function ttypeconvnode.first_load_smallset : tnode;
  1488. var
  1489. srsym: ttypesym;
  1490. p: tcallparanode;
  1491. begin
  1492. if not searchsystype('FPC_SMALL_SET',srsym) then
  1493. internalerror(200108313);
  1494. p := ccallparanode.create(left,nil);
  1495. { reused }
  1496. left := nil;
  1497. { convert parameter explicitely to fpc_small_set }
  1498. p.left := ctypeconvnode.create_explicit(p.left,srsym.restype);
  1499. { create call, adjust resulttype }
  1500. result :=
  1501. ccallnode.createinternres('fpc_set_load_small',p,resulttype);
  1502. firstpass(result);
  1503. end;
  1504. function ttypeconvnode.first_ansistring_to_pchar : tnode;
  1505. begin
  1506. first_ansistring_to_pchar:=nil;
  1507. expectloc:=LOC_REGISTER;
  1508. if registersint<1 then
  1509. registersint:=1;
  1510. end;
  1511. function ttypeconvnode.first_arrayconstructor_to_set : tnode;
  1512. begin
  1513. first_arrayconstructor_to_set:=nil;
  1514. internalerror(200104022);
  1515. end;
  1516. function ttypeconvnode.first_class_to_intf : tnode;
  1517. begin
  1518. first_class_to_intf:=nil;
  1519. expectloc:=LOC_REGISTER;
  1520. if registersint<1 then
  1521. registersint:=1;
  1522. end;
  1523. function ttypeconvnode._first_int_to_int : tnode;
  1524. begin
  1525. result:=first_int_to_int;
  1526. end;
  1527. function ttypeconvnode._first_cstring_to_pchar : tnode;
  1528. begin
  1529. result:=first_cstring_to_pchar;
  1530. end;
  1531. function ttypeconvnode._first_string_to_chararray : tnode;
  1532. begin
  1533. result:=first_string_to_chararray;
  1534. end;
  1535. function ttypeconvnode._first_char_to_string : tnode;
  1536. begin
  1537. result:=first_char_to_string;
  1538. end;
  1539. function ttypeconvnode._first_nothing : tnode;
  1540. begin
  1541. result:=first_nothing;
  1542. end;
  1543. function ttypeconvnode._first_array_to_pointer : tnode;
  1544. begin
  1545. result:=first_array_to_pointer;
  1546. end;
  1547. function ttypeconvnode._first_int_to_real : tnode;
  1548. begin
  1549. result:=first_int_to_real;
  1550. end;
  1551. function ttypeconvnode._first_real_to_real : tnode;
  1552. begin
  1553. result:=first_real_to_real;
  1554. end;
  1555. function ttypeconvnode._first_pointer_to_array : tnode;
  1556. begin
  1557. result:=first_pointer_to_array;
  1558. end;
  1559. function ttypeconvnode._first_cchar_to_pchar : tnode;
  1560. begin
  1561. result:=first_cchar_to_pchar;
  1562. end;
  1563. function ttypeconvnode._first_bool_to_int : tnode;
  1564. begin
  1565. result:=first_bool_to_int;
  1566. end;
  1567. function ttypeconvnode._first_int_to_bool : tnode;
  1568. begin
  1569. result:=first_int_to_bool;
  1570. end;
  1571. function ttypeconvnode._first_bool_to_bool : tnode;
  1572. begin
  1573. result:=first_bool_to_bool;
  1574. end;
  1575. function ttypeconvnode._first_proc_to_procvar : tnode;
  1576. begin
  1577. result:=first_proc_to_procvar;
  1578. end;
  1579. function ttypeconvnode._first_load_smallset : tnode;
  1580. begin
  1581. result:=first_load_smallset;
  1582. end;
  1583. function ttypeconvnode._first_cord_to_pointer : tnode;
  1584. begin
  1585. result:=first_cord_to_pointer;
  1586. end;
  1587. function ttypeconvnode._first_ansistring_to_pchar : tnode;
  1588. begin
  1589. result:=first_ansistring_to_pchar;
  1590. end;
  1591. function ttypeconvnode._first_arrayconstructor_to_set : tnode;
  1592. begin
  1593. result:=first_arrayconstructor_to_set;
  1594. end;
  1595. function ttypeconvnode._first_class_to_intf : tnode;
  1596. begin
  1597. result:=first_class_to_intf;
  1598. end;
  1599. function ttypeconvnode._first_char_to_char : tnode;
  1600. begin
  1601. result:=first_char_to_char;
  1602. end;
  1603. function ttypeconvnode.first_call_helper(c : tconverttype) : tnode;
  1604. const
  1605. firstconvert : array[tconverttype] of pointer = (
  1606. @ttypeconvnode._first_nothing, {equal}
  1607. @ttypeconvnode._first_nothing, {not_possible}
  1608. nil, { removed in resulttype_string_to_string }
  1609. @ttypeconvnode._first_char_to_string,
  1610. @ttypeconvnode._first_nothing, { char_2_chararray, needs nothing extra }
  1611. nil, { removed in resulttype_chararray_to_string }
  1612. @ttypeconvnode._first_cchar_to_pchar,
  1613. @ttypeconvnode._first_cstring_to_pchar,
  1614. @ttypeconvnode._first_ansistring_to_pchar,
  1615. @ttypeconvnode._first_string_to_chararray,
  1616. nil, { removed in resulttype_chararray_to_string }
  1617. @ttypeconvnode._first_array_to_pointer,
  1618. @ttypeconvnode._first_pointer_to_array,
  1619. @ttypeconvnode._first_int_to_int,
  1620. @ttypeconvnode._first_int_to_bool,
  1621. @ttypeconvnode._first_bool_to_bool,
  1622. @ttypeconvnode._first_bool_to_int,
  1623. @ttypeconvnode._first_real_to_real,
  1624. @ttypeconvnode._first_int_to_real,
  1625. nil, { removed in resulttype_real_to_currency }
  1626. @ttypeconvnode._first_proc_to_procvar,
  1627. @ttypeconvnode._first_arrayconstructor_to_set,
  1628. @ttypeconvnode._first_load_smallset,
  1629. @ttypeconvnode._first_cord_to_pointer,
  1630. @ttypeconvnode._first_nothing,
  1631. @ttypeconvnode._first_nothing,
  1632. @ttypeconvnode._first_class_to_intf,
  1633. @ttypeconvnode._first_char_to_char,
  1634. @ttypeconvnode._first_nothing,
  1635. @ttypeconvnode._first_nothing,
  1636. nil,
  1637. nil,
  1638. nil,
  1639. nil,
  1640. nil
  1641. );
  1642. type
  1643. tprocedureofobject = function : tnode of object;
  1644. var
  1645. r : packed record
  1646. proc : pointer;
  1647. obj : pointer;
  1648. end;
  1649. begin
  1650. { this is a little bit dirty but it works }
  1651. { and should be quite portable too }
  1652. r.proc:=firstconvert[c];
  1653. r.obj:=self;
  1654. if not assigned(r.proc) then
  1655. internalerror(200312081);
  1656. first_call_helper:=tprocedureofobject(r){$ifdef FPC}(){$endif FPC}
  1657. end;
  1658. function ttypeconvnode.pass_1 : tnode;
  1659. begin
  1660. result:=nil;
  1661. firstpass(left);
  1662. if codegenerror then
  1663. exit;
  1664. { load the value_str from the left part }
  1665. registersint:=left.registersint;
  1666. registersfpu:=left.registersfpu;
  1667. {$ifdef SUPPORT_MMX}
  1668. registersmmx:=left.registersmmx;
  1669. {$endif}
  1670. expectloc:=left.expectloc;
  1671. if (nf_explicit in flags) or
  1672. (nf_absolute in flags) then
  1673. begin
  1674. { check if the result could be in a register }
  1675. if not(tstoreddef(resulttype.def).is_intregable) and
  1676. not(tstoreddef(resulttype.def).is_fpuregable) then
  1677. make_not_regable(left);
  1678. end;
  1679. result:=first_call_helper(convtype);
  1680. end;
  1681. function ttypeconvnode.docompare(p: tnode) : boolean;
  1682. begin
  1683. docompare :=
  1684. inherited docompare(p) and
  1685. (convtype = ttypeconvnode(p).convtype);
  1686. end;
  1687. procedure ttypeconvnode._second_int_to_int;
  1688. begin
  1689. second_int_to_int;
  1690. end;
  1691. procedure ttypeconvnode._second_string_to_string;
  1692. begin
  1693. second_string_to_string;
  1694. end;
  1695. procedure ttypeconvnode._second_cstring_to_pchar;
  1696. begin
  1697. second_cstring_to_pchar;
  1698. end;
  1699. procedure ttypeconvnode._second_string_to_chararray;
  1700. begin
  1701. second_string_to_chararray;
  1702. end;
  1703. procedure ttypeconvnode._second_array_to_pointer;
  1704. begin
  1705. second_array_to_pointer;
  1706. end;
  1707. procedure ttypeconvnode._second_pointer_to_array;
  1708. begin
  1709. second_pointer_to_array;
  1710. end;
  1711. procedure ttypeconvnode._second_chararray_to_string;
  1712. begin
  1713. second_chararray_to_string;
  1714. end;
  1715. procedure ttypeconvnode._second_char_to_string;
  1716. begin
  1717. second_char_to_string;
  1718. end;
  1719. procedure ttypeconvnode._second_int_to_real;
  1720. begin
  1721. second_int_to_real;
  1722. end;
  1723. procedure ttypeconvnode._second_real_to_real;
  1724. begin
  1725. second_real_to_real;
  1726. end;
  1727. procedure ttypeconvnode._second_cord_to_pointer;
  1728. begin
  1729. second_cord_to_pointer;
  1730. end;
  1731. procedure ttypeconvnode._second_proc_to_procvar;
  1732. begin
  1733. second_proc_to_procvar;
  1734. end;
  1735. procedure ttypeconvnode._second_bool_to_int;
  1736. begin
  1737. second_bool_to_int;
  1738. end;
  1739. procedure ttypeconvnode._second_int_to_bool;
  1740. begin
  1741. second_int_to_bool;
  1742. end;
  1743. procedure ttypeconvnode._second_bool_to_bool;
  1744. begin
  1745. second_bool_to_bool;
  1746. end;
  1747. procedure ttypeconvnode._second_load_smallset;
  1748. begin
  1749. second_load_smallset;
  1750. end;
  1751. procedure ttypeconvnode._second_ansistring_to_pchar;
  1752. begin
  1753. second_ansistring_to_pchar;
  1754. end;
  1755. procedure ttypeconvnode._second_class_to_intf;
  1756. begin
  1757. second_class_to_intf;
  1758. end;
  1759. procedure ttypeconvnode._second_char_to_char;
  1760. begin
  1761. second_char_to_char;
  1762. end;
  1763. procedure ttypeconvnode._second_nothing;
  1764. begin
  1765. second_nothing;
  1766. end;
  1767. procedure ttypeconvnode.second_call_helper(c : tconverttype);
  1768. {$ifdef fpc}
  1769. const
  1770. secondconvert : array[tconverttype] of pointer = (
  1771. @_second_nothing, {equal}
  1772. @_second_nothing, {not_possible}
  1773. @_second_nothing, {second_string_to_string, handled in resulttype pass }
  1774. @_second_char_to_string,
  1775. @_second_nothing, {char_to_charray}
  1776. @_second_nothing, { pchar_to_string, handled in resulttype pass }
  1777. @_second_nothing, {cchar_to_pchar}
  1778. @_second_cstring_to_pchar,
  1779. @_second_ansistring_to_pchar,
  1780. @_second_string_to_chararray,
  1781. @_second_nothing, { chararray_to_string, handled in resulttype pass }
  1782. @_second_array_to_pointer,
  1783. @_second_pointer_to_array,
  1784. @_second_int_to_int,
  1785. @_second_int_to_bool,
  1786. @_second_bool_to_bool,
  1787. @_second_bool_to_int,
  1788. @_second_real_to_real,
  1789. @_second_int_to_real,
  1790. @_second_nothing, { real_to_currency, handled in resulttype pass }
  1791. @_second_proc_to_procvar,
  1792. @_second_nothing, { arrayconstructor_to_set }
  1793. @_second_nothing, { second_load_smallset, handled in first pass }
  1794. @_second_cord_to_pointer,
  1795. @_second_nothing, { interface 2 string }
  1796. @_second_nothing, { interface 2 guid }
  1797. @_second_class_to_intf,
  1798. @_second_char_to_char,
  1799. @_second_nothing, { normal_2_smallset }
  1800. @_second_nothing, { dynarray_2_openarray }
  1801. @_second_nothing, { pwchar_2_string }
  1802. @_second_nothing, { variant_2_dynarray }
  1803. @_second_nothing, { dynarray_2_variant}
  1804. @_second_nothing, { variant_2_enum }
  1805. @_second_nothing { enum_2_variant }
  1806. );
  1807. type
  1808. tprocedureofobject = procedure of object;
  1809. var
  1810. r : packed record
  1811. proc : pointer;
  1812. obj : pointer;
  1813. end;
  1814. begin
  1815. { this is a little bit dirty but it works }
  1816. { and should be quite portable too }
  1817. r.proc:=secondconvert[c];
  1818. r.obj:=self;
  1819. tprocedureofobject(r)();
  1820. end;
  1821. {$else fpc}
  1822. begin
  1823. case c of
  1824. tc_equal,
  1825. tc_not_possible,
  1826. tc_string_2_string : second_nothing;
  1827. tc_char_2_string : second_char_to_string;
  1828. tc_char_2_chararray : second_nothing;
  1829. tc_pchar_2_string : second_nothing;
  1830. tc_cchar_2_pchar : second_nothing;
  1831. tc_cstring_2_pchar : second_cstring_to_pchar;
  1832. tc_ansistring_2_pchar : second_ansistring_to_pchar;
  1833. tc_string_2_chararray : second_string_to_chararray;
  1834. tc_chararray_2_string : second_nothing;
  1835. tc_array_2_pointer : second_array_to_pointer;
  1836. tc_pointer_2_array : second_pointer_to_array;
  1837. tc_int_2_int : second_int_to_int;
  1838. tc_int_2_bool : second_int_to_bool;
  1839. tc_bool_2_bool : second_bool_to_bool;
  1840. tc_bool_2_int : second_bool_to_int;
  1841. tc_real_2_real : second_real_to_real;
  1842. tc_int_2_real : second_int_to_real;
  1843. tc_real_2_currency : second_nothing;
  1844. tc_proc_2_procvar : second_proc_to_procvar;
  1845. tc_arrayconstructor_2_set : second_nothing;
  1846. tc_load_smallset : second_nothing;
  1847. tc_cord_2_pointer : second_cord_to_pointer;
  1848. tc_intf_2_string : second_nothing;
  1849. tc_intf_2_guid : second_nothing;
  1850. tc_class_2_intf : second_class_to_intf;
  1851. tc_char_2_char : second_char_to_char;
  1852. tc_normal_2_smallset : second_nothing;
  1853. tc_dynarray_2_openarray : second_nothing;
  1854. tc_pwchar_2_string : second_nothing;
  1855. tc_variant_2_dynarray : second_nothing;
  1856. tc_dynarray_2_variant : second_nothing;
  1857. else internalerror(2002101101);
  1858. end;
  1859. end;
  1860. {$endif fpc}
  1861. {*****************************************************************************
  1862. TISNODE
  1863. *****************************************************************************}
  1864. constructor tisnode.create(l,r : tnode);
  1865. begin
  1866. inherited create(isn,l,r);
  1867. end;
  1868. function tisnode.det_resulttype:tnode;
  1869. var
  1870. paras: tcallparanode;
  1871. begin
  1872. result:=nil;
  1873. resulttypepass(left);
  1874. resulttypepass(right);
  1875. set_varstate(left,vs_used,true);
  1876. set_varstate(right,vs_used,true);
  1877. if codegenerror then
  1878. exit;
  1879. if (right.resulttype.def.deftype=classrefdef) then
  1880. begin
  1881. { left must be a class }
  1882. if is_class(left.resulttype.def) then
  1883. begin
  1884. { the operands must be related }
  1885. if (not(tobjectdef(left.resulttype.def).is_related(
  1886. tobjectdef(tclassrefdef(right.resulttype.def).pointertype.def)))) and
  1887. (not(tobjectdef(tclassrefdef(right.resulttype.def).pointertype.def).is_related(
  1888. tobjectdef(left.resulttype.def)))) then
  1889. CGMessage2(type_e_classes_not_related,left.resulttype.def.typename,
  1890. tclassrefdef(right.resulttype.def).pointertype.def.typename);
  1891. end
  1892. else
  1893. CGMessage1(type_e_class_type_expected,left.resulttype.def.typename);
  1894. { call fpc_do_is helper }
  1895. paras := ccallparanode.create(
  1896. left,
  1897. ccallparanode.create(
  1898. right,nil));
  1899. result := ccallnode.createintern('fpc_do_is',paras);
  1900. left := nil;
  1901. right := nil;
  1902. end
  1903. else if is_interface(right.resulttype.def) then
  1904. begin
  1905. { left is a class }
  1906. if is_class(left.resulttype.def) then
  1907. begin
  1908. { the operands must be related }
  1909. if not(assigned(tobjectdef(left.resulttype.def).implementedinterfaces) and
  1910. (tobjectdef(left.resulttype.def).implementedinterfaces.searchintf(right.resulttype.def)<>-1)) then
  1911. CGMessage2(type_e_classes_not_related,left.resulttype.def.typename,right.resulttype.def.typename);
  1912. end
  1913. { left is an interface }
  1914. else if is_interface(left.resulttype.def) then
  1915. begin
  1916. { the operands must be related }
  1917. if (not(tobjectdef(left.resulttype.def).is_related(tobjectdef(right.resulttype.def)))) and
  1918. (not(tobjectdef(right.resulttype.def).is_related(tobjectdef(left.resulttype.def)))) then
  1919. CGMessage(type_e_mismatch);
  1920. end
  1921. else
  1922. CGMessage1(type_e_class_type_expected,left.resulttype.def.typename);
  1923. { call fpc_do_is helper }
  1924. paras := ccallparanode.create(
  1925. left,
  1926. ccallparanode.create(
  1927. right,nil));
  1928. result := ccallnode.createintern('fpc_do_is',paras);
  1929. left := nil;
  1930. right := nil;
  1931. end
  1932. else
  1933. CGMessage1(type_e_class_or_interface_type_expected,right.resulttype.def.typename);
  1934. resulttype:=booltype;
  1935. end;
  1936. function tisnode.pass_1 : tnode;
  1937. begin
  1938. internalerror(200204254);
  1939. result:=nil;
  1940. end;
  1941. { dummy pass_2, it will never be called, but we need one since }
  1942. { you can't instantiate an abstract class }
  1943. procedure tisnode.pass_2;
  1944. begin
  1945. end;
  1946. {*****************************************************************************
  1947. TASNODE
  1948. *****************************************************************************}
  1949. constructor tasnode.create(l,r : tnode);
  1950. begin
  1951. inherited create(asn,l,r);
  1952. call := nil;
  1953. end;
  1954. destructor tasnode.destroy;
  1955. begin
  1956. call.free;
  1957. inherited destroy;
  1958. end;
  1959. function tasnode.det_resulttype:tnode;
  1960. var
  1961. hp : tnode;
  1962. begin
  1963. result:=nil;
  1964. resulttypepass(right);
  1965. resulttypepass(left);
  1966. set_varstate(right,vs_used,true);
  1967. set_varstate(left,vs_used,true);
  1968. if codegenerror then
  1969. exit;
  1970. if (right.resulttype.def.deftype=classrefdef) then
  1971. begin
  1972. { left must be a class }
  1973. if is_class(left.resulttype.def) then
  1974. begin
  1975. { the operands must be related }
  1976. if (not(tobjectdef(left.resulttype.def).is_related(
  1977. tobjectdef(tclassrefdef(right.resulttype.def).pointertype.def)))) and
  1978. (not(tobjectdef(tclassrefdef(right.resulttype.def).pointertype.def).is_related(
  1979. tobjectdef(left.resulttype.def)))) then
  1980. CGMessage2(type_e_classes_not_related,left.resulttype.def.typename,
  1981. tclassrefdef(right.resulttype.def).pointertype.def.typename);
  1982. end
  1983. else
  1984. CGMessage1(type_e_class_type_expected,left.resulttype.def.typename);
  1985. resulttype:=tclassrefdef(right.resulttype.def).pointertype;
  1986. end
  1987. else if is_interface(right.resulttype.def) then
  1988. begin
  1989. { left is a class }
  1990. if is_class(left.resulttype.def) then
  1991. begin
  1992. { the operands must be related
  1993. no, because the class instance could be a child class of the current one which
  1994. implements additional interfaces (FK)
  1995. b:=false;
  1996. o:=tobjectdef(left.resulttype.def);
  1997. while assigned(o) do
  1998. begin
  1999. if assigned(o.implementedinterfaces) and
  2000. (o.implementedinterfaces.searchintf(right.resulttype.def)<>-1) then
  2001. begin
  2002. b:=true;
  2003. break;
  2004. end;
  2005. o:=o.childof;
  2006. end;
  2007. if not(b) then
  2008. CGMessage2(type_e_classes_not_related,left.resulttype.def.typename,right.resulttype.def.typename);
  2009. }
  2010. end
  2011. { left is an interface }
  2012. else if is_interface(left.resulttype.def) then
  2013. begin
  2014. { the operands must be related
  2015. we don't necessarily know how the both interfaces are implemented, so we can't do this check (FK)
  2016. if (not(tobjectdef(left.resulttype.def).is_related(tobjectdef(right.resulttype.def)))) and
  2017. (not(tobjectdef(right.resulttype.def).is_related(tobjectdef(left.resulttype.def)))) then
  2018. CGMessage2(type_e_classes_not_related,left.resulttype.def.typename,right.resulttype.def.typename);
  2019. }
  2020. end
  2021. else
  2022. CGMessage1(type_e_class_type_expected,left.resulttype.def.typename);
  2023. resulttype:=right.resulttype;
  2024. { load the GUID of the interface }
  2025. if (right.nodetype=typen) then
  2026. begin
  2027. if assigned(tobjectdef(right.resulttype.def).iidguid) then
  2028. begin
  2029. hp:=cguidconstnode.create(tobjectdef(right.resulttype.def).iidguid^);
  2030. right.free;
  2031. right:=hp;
  2032. end
  2033. else
  2034. internalerror(200206282);
  2035. resulttypepass(right);
  2036. end;
  2037. end
  2038. else
  2039. CGMessage1(type_e_class_or_interface_type_expected,right.resulttype.def.typename);
  2040. end;
  2041. function tasnode.getcopy: tnode;
  2042. begin
  2043. result := inherited getcopy;
  2044. if assigned(call) then
  2045. tasnode(result).call := call.getcopy
  2046. else
  2047. tasnode(result).call := nil;
  2048. end;
  2049. function tasnode.pass_1 : tnode;
  2050. var
  2051. procname: string;
  2052. begin
  2053. result:=nil;
  2054. if not assigned(call) then
  2055. begin
  2056. if is_class(left.resulttype.def) and
  2057. (right.resulttype.def.deftype=classrefdef) then
  2058. call := ccallnode.createinternres('fpc_do_as',
  2059. ccallparanode.create(left,ccallparanode.create(right,nil)),
  2060. resulttype)
  2061. else
  2062. begin
  2063. if is_class(left.resulttype.def) then
  2064. procname := 'fpc_class_as_intf'
  2065. else
  2066. procname := 'fpc_intf_as';
  2067. call := ccallnode.createinternres(procname,
  2068. ccallparanode.create(right,ccallparanode.create(left,nil)),
  2069. resulttype);
  2070. end;
  2071. left := nil;
  2072. right := nil;
  2073. firstpass(call);
  2074. if codegenerror then
  2075. exit;
  2076. expectloc:=call.expectloc;
  2077. registersint:=call.registersint;
  2078. registersfpu:=call.registersfpu;
  2079. {$ifdef SUPPORT_MMX}
  2080. registersmmx:=call.registersmmx;
  2081. {$endif SUPPORT_MMX}
  2082. end;
  2083. end;
  2084. begin
  2085. ctypeconvnode:=ttypeconvnode;
  2086. casnode:=tasnode;
  2087. cisnode:=tisnode;
  2088. end.
  2089. {
  2090. $Log$
  2091. Revision 1.139 2004-02-13 15:42:21 peter
  2092. * compare_defs_ext has now a options argument
  2093. * fixes for variants
  2094. Revision 1.138 2004/02/05 01:24:08 florian
  2095. * several fixes to compile x86-64 system
  2096. Revision 1.137 2004/02/04 22:15:15 daniel
  2097. * Rtti generation moved to ncgutil
  2098. * Assmtai usage of symsym removed
  2099. * operator overloading cleanup up
  2100. Revision 1.136 2004/02/03 22:32:54 peter
  2101. * renamed xNNbittype to xNNinttype
  2102. * renamed registers32 to registersint
  2103. * replace some s32bit,u32bit with torddef([su]inttype).def.typ
  2104. Revision 1.135 2004/01/26 16:12:27 daniel
  2105. * reginfo now also only allocated during register allocation
  2106. * third round of gdb cleanups: kick out most of concatstabto
  2107. Revision 1.134 2003/12/26 00:32:21 florian
  2108. + fpu<->mm register conversion
  2109. Revision 1.133 2003/12/22 23:11:15 peter
  2110. * fix rangecheck error
  2111. Revision 1.132 2003/12/08 22:35:28 peter
  2112. * again procvar fixes
  2113. Revision 1.131 2003/11/22 00:31:52 jonas
  2114. * fixed range error
  2115. Revision 1.130 2003/11/04 22:30:15 florian
  2116. + type cast variant<->enum
  2117. * cnv. node second pass uses now as well helper wrappers
  2118. Revision 1.129 2003/10/31 18:42:03 peter
  2119. * don't call proc_to_procvar for explicit typecasts
  2120. Revision 1.128 2003/10/29 22:01:20 florian
  2121. * fixed passing of dyn. arrays to open array parameters
  2122. Revision 1.127 2003/10/28 15:36:01 peter
  2123. * absolute to object field supported, fixes tb0458
  2124. Revision 1.126 2003/10/23 14:44:07 peter
  2125. * splitted buildderef and buildderefimpl to fix interface crc
  2126. calculation
  2127. Revision 1.125 2003/10/22 20:40:00 peter
  2128. * write derefdata in a separate ppu entry
  2129. Revision 1.124 2003/10/21 18:16:13 peter
  2130. * IncompatibleTypes() added that will include unit names when
  2131. the typenames are the same
  2132. Revision 1.123 2003/10/09 14:39:03 peter
  2133. * allow explicit typecasts from classrefdef, fixes 2728
  2134. Revision 1.122 2003/10/08 19:19:45 peter
  2135. * set_varstate cleanup
  2136. Revision 1.121 2003/10/07 14:30:27 peter
  2137. * fix 2720
  2138. Revision 1.120 2003/10/01 20:34:48 peter
  2139. * procinfo unit contains tprocinfo
  2140. * cginfo renamed to cgbase
  2141. * moved cgmessage to verbose
  2142. * fixed ppc and sparc compiles
  2143. Revision 1.119 2003/09/25 14:57:51 peter
  2144. * fix different expectloc
  2145. Revision 1.118 2003/09/06 22:27:08 florian
  2146. * fixed web bug 2669
  2147. * cosmetic fix in printnode
  2148. * tobjectdef.gettypename implemented
  2149. Revision 1.117 2003/09/03 15:55:01 peter
  2150. * NEWRA branch merged
  2151. Revision 1.116 2003/08/10 17:25:23 peter
  2152. * fixed some reported bugs
  2153. Revision 1.115 2003/06/05 20:05:55 peter
  2154. * removed changesettype because that will change the definition
  2155. of the setdef forever and can result in a different between
  2156. original interface and current implementation definition
  2157. Revision 1.114 2003/06/04 17:55:09 jonas
  2158. * disable fpuregable for fpu variables typecasted to non fpu-type
  2159. Revision 1.113 2003/06/04 17:29:01 jonas
  2160. * fixed void_to_(int,pointer) typeconversion
  2161. Revision 1.112 2003/06/03 21:05:48 peter
  2162. * fix check for procedure without parameters
  2163. * calling constructor as member will not allocate memory
  2164. Revision 1.111 2003/05/11 21:37:03 peter
  2165. * moved implicit exception frame from ncgutil to psub
  2166. * constructor/destructor helpers moved from cobj/ncgutil to psub
  2167. Revision 1.110 2003/05/09 17:47:02 peter
  2168. * self moved to hidden parameter
  2169. * removed hdisposen,hnewn,selfn
  2170. Revision 1.109 2003/04/27 11:21:33 peter
  2171. * aktprocdef renamed to current_procdef
  2172. * procinfo renamed to current_procinfo
  2173. * procinfo will now be stored in current_module so it can be
  2174. cleaned up properly
  2175. * gen_main_procsym changed to create_main_proc and release_main_proc
  2176. to also generate a tprocinfo structure
  2177. * fixed unit implicit initfinal
  2178. Revision 1.108 2003/04/23 20:16:04 peter
  2179. + added currency support based on int64
  2180. + is_64bit for use in cg units instead of is_64bitint
  2181. * removed cgmessage from n386add, replace with internalerrors
  2182. Revision 1.107 2003/04/23 13:13:08 peter
  2183. * fix checking of procdef type which was broken since loadn returned
  2184. pointertype for tp procvar
  2185. Revision 1.106 2003/04/23 10:10:07 peter
  2186. * expectloc fixes
  2187. Revision 1.105 2003/04/22 23:50:23 peter
  2188. * firstpass uses expectloc
  2189. * checks if there are differences between the expectloc and
  2190. location.loc from secondpass in EXTDEBUG
  2191. Revision 1.104 2003/04/22 09:52:30 peter
  2192. * do not convert procvars with void return to callnode
  2193. Revision 1.103 2003/03/17 18:54:23 peter
  2194. * fix missing self setting for method to procvar conversion in
  2195. tp_procvar mode
  2196. Revision 1.102 2003/02/15 22:15:57 carl
  2197. * generic conversaion routines only work on signed types
  2198. Revision 1.101 2003/01/16 22:13:52 peter
  2199. * convert_l3 convertlevel added. This level is used for conversions
  2200. where information can be lost like converting widestring->ansistring
  2201. or dword->byte
  2202. Revision 1.100 2003/01/15 01:44:32 peter
  2203. * merged methodpointer fixes from 1.0.x
  2204. Revision 1.99 2003/01/09 21:43:39 peter
  2205. * constant string conversion fixed, it's now equal to both
  2206. shortstring, ansistring and the typeconvnode will return
  2207. te_equal but still return convtype to change the constnode
  2208. Revision 1.98 2003/01/05 22:41:40 peter
  2209. * move code that checks for longint-pointer conversion hint
  2210. Revision 1.97 2003/01/03 12:15:56 daniel
  2211. * Removed ifdefs around notifications
  2212. ifdefs around for loop optimizations remain
  2213. Revision 1.96 2002/12/22 16:34:49 peter
  2214. * proc-procvar crash fixed (tw2277)
  2215. Revision 1.95 2002/12/20 16:01:26 peter
  2216. * don't allow class(classref) conversion
  2217. Revision 1.94 2002/12/05 14:27:26 florian
  2218. * some variant <-> dyn. array stuff
  2219. Revision 1.93 2002/11/30 10:45:14 carl
  2220. * fix bug with checking of duplicated items in sets (new sets bug only)
  2221. Revision 1.92 2002/11/27 19:43:21 carl
  2222. * updated notes and hints
  2223. Revision 1.91 2002/11/27 13:11:38 peter
  2224. * more currency fixes, taddcurr runs now successfull
  2225. Revision 1.90 2002/11/27 11:29:21 peter
  2226. * when converting from and to currency divide or multiple the
  2227. result by 10000
  2228. Revision 1.89 2002/11/25 17:43:18 peter
  2229. * splitted defbase in defutil,symutil,defcmp
  2230. * merged isconvertable and is_equal into compare_defs(_ext)
  2231. * made operator search faster by walking the list only once
  2232. Revision 1.88 2002/11/17 16:31:56 carl
  2233. * memory optimization (3-4%) : cleanup of tai fields,
  2234. cleanup of tdef and tsym fields.
  2235. * make it work for m68k
  2236. Revision 1.87 2002/10/10 16:07:57 florian
  2237. + several widestring/pwidechar related stuff added
  2238. Revision 1.86 2002/10/06 16:10:23 florian
  2239. * when compiling <interface> as <interface> we can't assume
  2240. anything about relation
  2241. Revision 1.85 2002/10/05 12:43:25 carl
  2242. * fixes for Delphi 6 compilation
  2243. (warning : Some features do not work under Delphi)
  2244. Revision 1.84 2002/10/02 20:23:50 florian
  2245. - removed the relation check for <class> as <interface> because we don't
  2246. know the runtime type of <class>! It could be a child class of the given type
  2247. which implements additional interfaces
  2248. Revision 1.83 2002/10/02 20:17:14 florian
  2249. + the as operator for <class> as <interface> has to check the parent classes as well
  2250. Revision 1.82 2002/09/30 07:00:47 florian
  2251. * fixes to common code to get the alpha compiler compiled applied
  2252. Revision 1.81 2002/09/16 14:11:13 peter
  2253. * add argument to equal_paras() to support default values or not
  2254. Revision 1.80 2002/09/07 20:40:23 carl
  2255. * cardinal -> longword
  2256. Revision 1.79 2002/09/07 15:25:03 peter
  2257. * old logs removed and tabs fixed
  2258. Revision 1.78 2002/09/07 12:16:04 carl
  2259. * second part bug report 1996 fix, testrange in cordconstnode
  2260. only called if option is set (also make parsing a tiny faster)
  2261. Revision 1.77 2002/09/05 05:56:07 jonas
  2262. - reverted my last commit, it was completely bogus :(
  2263. Revision 1.75 2002/09/02 19:24:42 peter
  2264. * array of char support for Str()
  2265. Revision 1.74 2002/09/01 08:01:16 daniel
  2266. * Removed sets from Tcallnode.det_resulttype
  2267. + Added read/write notifications of variables. These will be usefull
  2268. for providing information for several optimizations. For example
  2269. the value of the loop variable of a for loop does matter is the
  2270. variable is read after the for loop, but if it's no longer used
  2271. or written, it doesn't matter and this can be used to optimize
  2272. the loop code generation.
  2273. Revision 1.73 2002/08/23 16:14:49 peter
  2274. * tempgen cleanup
  2275. * tt_noreuse temp type added that will be used in genentrycode
  2276. Revision 1.72 2002/08/20 18:23:33 jonas
  2277. * the as node again uses a compilerproc
  2278. + (untested) support for interface "as" statements
  2279. Revision 1.71 2002/08/19 19:36:43 peter
  2280. * More fixes for cross unit inlining, all tnodes are now implemented
  2281. * Moved pocall_internconst to po_internconst because it is not a
  2282. calling type at all and it conflicted when inlining of these small
  2283. functions was requested
  2284. Revision 1.70 2002/08/17 09:23:36 florian
  2285. * first part of current_procinfo rewrite
  2286. Revision 1.69 2002/08/14 19:26:55 carl
  2287. + generic int_to_real type conversion
  2288. + generic unaryminus node
  2289. Revision 1.68 2002/08/11 16:08:55 florian
  2290. + support of explicit type case boolean->char
  2291. Revision 1.67 2002/08/11 15:28:00 florian
  2292. + support of explicit type case <any ordinal type>->pointer
  2293. (delphi mode only)
  2294. Revision 1.66 2002/08/09 07:33:01 florian
  2295. * a couple of interface related fixes
  2296. Revision 1.65 2002/07/29 21:23:42 florian
  2297. * more fixes for the ppc
  2298. + wrappers for the tcnvnode.first_* stuff introduced
  2299. Revision 1.64 2002/07/23 12:34:30 daniel
  2300. * Readded old set code. To use it define 'oldset'. Activated by default
  2301. for ppc.
  2302. Revision 1.63 2002/07/23 09:51:22 daniel
  2303. * Tried to make Tprocsym.defs protected. I didn't succeed but the cleanups
  2304. are worth comitting.
  2305. Revision 1.62 2002/07/22 11:48:04 daniel
  2306. * Sets are now internally sets.
  2307. Revision 1.61 2002/07/20 17:16:02 florian
  2308. + source code page support
  2309. Revision 1.60 2002/07/20 11:57:54 florian
  2310. * types.pas renamed to defbase.pas because D6 contains a types
  2311. unit so this would conflicts if D6 programms are compiled
  2312. + Willamette/SSE2 instructions to assembler added
  2313. Revision 1.59 2002/07/01 16:23:53 peter
  2314. * cg64 patch
  2315. * basics for currency
  2316. * asnode updates for class and interface (not finished)
  2317. Revision 1.58 2002/05/18 13:34:09 peter
  2318. * readded missing revisions
  2319. }