ncnv.pas 92 KB

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