ncnv.pas 96 KB

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