ncnv.pas 93 KB

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