ncnv.pas 72 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104
  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,symppu,
  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 derefimpl;override;
  39. function getcopy : tnode;override;
  40. function pass_1 : tnode;override;
  41. function det_resulttype:tnode;override;
  42. {$ifdef var_notification}
  43. procedure mark_write;override;
  44. {$endif}
  45. function docompare(p: tnode) : boolean; override;
  46. private
  47. function resulttype_cord_to_pointer : tnode;
  48. function resulttype_chararray_to_string : tnode;
  49. function resulttype_string_to_chararray : tnode;
  50. function resulttype_string_to_string : tnode;
  51. function resulttype_char_to_string : tnode;
  52. function resulttype_char_to_chararray : tnode;
  53. function resulttype_int_to_real : tnode;
  54. function resulttype_real_to_real : tnode;
  55. function resulttype_cchar_to_pchar : tnode;
  56. function resulttype_cstring_to_pchar : tnode;
  57. function resulttype_char_to_char : tnode;
  58. function resulttype_arrayconstructor_to_set : tnode;
  59. function resulttype_pchar_to_string : tnode;
  60. function resulttype_interface_to_guid : tnode;
  61. function resulttype_dynarray_to_openarray : tnode;
  62. function resulttype_pwchar_to_string : tnode;
  63. function resulttype_call_helper(c : tconverttype) : tnode;
  64. protected
  65. function first_int_to_int : tnode;virtual;
  66. function first_cstring_to_pchar : tnode;virtual;
  67. function first_string_to_chararray : tnode;virtual;
  68. function first_char_to_string : tnode;virtual;
  69. function first_nothing : tnode;virtual;
  70. function first_array_to_pointer : tnode;virtual;
  71. function first_int_to_real : tnode;virtual;
  72. function first_real_to_real : tnode;virtual;
  73. function first_pointer_to_array : tnode;virtual;
  74. function first_cchar_to_pchar : tnode;virtual;
  75. function first_bool_to_int : tnode;virtual;
  76. function first_int_to_bool : tnode;virtual;
  77. function first_bool_to_bool : tnode;virtual;
  78. function first_proc_to_procvar : tnode;virtual;
  79. function first_load_smallset : tnode;virtual;
  80. function first_cord_to_pointer : tnode;virtual;
  81. function first_ansistring_to_pchar : tnode;virtual;
  82. function first_arrayconstructor_to_set : tnode;virtual;
  83. function first_class_to_intf : tnode;virtual;
  84. function first_char_to_char : tnode;virtual;
  85. function first_call_helper(c : tconverttype) : tnode;
  86. { these wrapper are necessary, because the first_* stuff is called }
  87. { through a table. Without the wrappers override wouldn't have }
  88. { any effect }
  89. function _first_int_to_int : tnode;
  90. function _first_cstring_to_pchar : tnode;
  91. function _first_string_to_chararray : tnode;
  92. function _first_char_to_string : tnode;
  93. function _first_nothing : tnode;
  94. function _first_array_to_pointer : tnode;
  95. function _first_int_to_real : tnode;
  96. function _first_real_to_real : tnode;
  97. function _first_pointer_to_array : tnode;
  98. function _first_cchar_to_pchar : tnode;
  99. function _first_bool_to_int : tnode;
  100. function _first_int_to_bool : tnode;
  101. function _first_bool_to_bool : tnode;
  102. function _first_proc_to_procvar : tnode;
  103. function _first_load_smallset : tnode;
  104. function _first_cord_to_pointer : tnode;
  105. function _first_ansistring_to_pchar : tnode;
  106. function _first_arrayconstructor_to_set : tnode;
  107. function _first_class_to_intf : tnode;
  108. function _first_char_to_char : tnode;
  109. procedure second_int_to_int;virtual;abstract;
  110. procedure second_string_to_string;virtual;abstract;
  111. procedure second_cstring_to_pchar;virtual;abstract;
  112. procedure second_string_to_chararray;virtual;abstract;
  113. procedure second_array_to_pointer;virtual;abstract;
  114. procedure second_pointer_to_array;virtual;abstract;
  115. procedure second_chararray_to_string;virtual;abstract;
  116. procedure second_char_to_string;virtual;abstract;
  117. procedure second_int_to_real;virtual;abstract;
  118. procedure second_real_to_real;virtual;abstract;
  119. procedure second_cord_to_pointer;virtual;abstract;
  120. procedure second_proc_to_procvar;virtual;abstract;
  121. procedure second_bool_to_int;virtual;abstract;
  122. procedure second_int_to_bool;virtual;abstract;
  123. procedure second_bool_to_bool;virtual;abstract;
  124. procedure second_load_smallset;virtual;abstract;
  125. procedure second_ansistring_to_pchar;virtual;abstract;
  126. procedure second_class_to_intf;virtual;abstract;
  127. procedure second_char_to_char;virtual;abstract;
  128. procedure second_nothing; virtual;abstract;
  129. end;
  130. ttypeconvnodeclass = class of ttypeconvnode;
  131. tasnode = class(tbinarynode)
  132. constructor create(l,r : tnode);virtual;
  133. function pass_1 : tnode;override;
  134. function det_resulttype:tnode;override;
  135. function getcopy: tnode;override;
  136. destructor destroy; override;
  137. protected
  138. call: tnode;
  139. end;
  140. tasnodeclass = class of tasnode;
  141. tisnode = class(tbinarynode)
  142. constructor create(l,r : tnode);virtual;
  143. function pass_1 : tnode;override;
  144. function det_resulttype:tnode;override;
  145. procedure pass_2;override;
  146. end;
  147. tisnodeclass = class of tisnode;
  148. var
  149. ctypeconvnode : ttypeconvnodeclass;
  150. casnode : tasnodeclass;
  151. cisnode : tisnodeclass;
  152. procedure inserttypeconv(var p:tnode;const t:ttype);
  153. procedure inserttypeconv_explicit(var p:tnode;const t:ttype);
  154. procedure arrayconstructor_to_set(var p : tnode);
  155. implementation
  156. uses
  157. globtype,systems,tokens,
  158. cutils,verbose,globals,widestr,
  159. symconst,symdef,symsym,symtable,
  160. ncon,ncal,nset,nadd,ninl,nmem,nmat,
  161. cgbase,
  162. htypechk,pass_1,cpubase,cpuinfo;
  163. {*****************************************************************************
  164. Helpers
  165. *****************************************************************************}
  166. procedure inserttypeconv(var p:tnode;const t:ttype);
  167. begin
  168. if not assigned(p.resulttype.def) then
  169. begin
  170. resulttypepass(p);
  171. if codegenerror then
  172. exit;
  173. end;
  174. { don't insert obsolete type conversions }
  175. if equal_defs(p.resulttype.def,t.def) and
  176. not ((p.resulttype.def.deftype=setdef) and
  177. (tsetdef(p.resulttype.def).settype <>
  178. tsetdef(t.def).settype)) then
  179. begin
  180. p.resulttype:=t;
  181. end
  182. else
  183. begin
  184. p:=ctypeconvnode.create(p,t);
  185. resulttypepass(p);
  186. end;
  187. end;
  188. procedure inserttypeconv_explicit(var p:tnode;const t:ttype);
  189. begin
  190. if not assigned(p.resulttype.def) then
  191. begin
  192. resulttypepass(p);
  193. if codegenerror then
  194. exit;
  195. end;
  196. { don't insert obsolete type conversions }
  197. if equal_defs(p.resulttype.def,t.def) and
  198. not ((p.resulttype.def.deftype=setdef) and
  199. (tsetdef(p.resulttype.def).settype <>
  200. tsetdef(t.def).settype)) then
  201. begin
  202. p.resulttype:=t;
  203. end
  204. else
  205. begin
  206. p:=ctypeconvnode.create_explicit(p,t);
  207. resulttypepass(p);
  208. end;
  209. end;
  210. {*****************************************************************************
  211. Array constructor to Set Conversion
  212. *****************************************************************************}
  213. procedure arrayconstructor_to_set(var p : tnode);
  214. var
  215. constp : tsetconstnode;
  216. buildp,
  217. p2,p3,p4 : tnode;
  218. htype : ttype;
  219. constset : Pconstset;
  220. constsetlo,
  221. constsethi : longint;
  222. procedure update_constsethi(t:ttype);
  223. begin
  224. if ((t.def.deftype=orddef) and
  225. (torddef(t.def).high>=constsethi)) then
  226. begin
  227. constsethi:=torddef(t.def).high;
  228. if htype.def=nil then
  229. begin
  230. if (constsethi>255) or
  231. (torddef(t.def).low<0) then
  232. htype:=u8bittype
  233. else
  234. htype:=t;
  235. end;
  236. if constsethi>255 then
  237. constsethi:=255;
  238. end
  239. else if ((t.def.deftype=enumdef) and
  240. (tenumdef(t.def).max>=constsethi)) then
  241. begin
  242. if htype.def=nil then
  243. htype:=t;
  244. constsethi:=tenumdef(t.def).max;
  245. end;
  246. end;
  247. procedure do_set(pos : longint);
  248. {$ifdef oldset}
  249. var
  250. mask,l : longint;
  251. {$endif}
  252. begin
  253. if (pos and not $ff)<>0 then
  254. Message(parser_e_illegal_set_expr);
  255. if pos>constsethi then
  256. constsethi:=pos;
  257. if pos<constsetlo then
  258. constsetlo:=pos;
  259. {$ifdef oldset}
  260. { to do this correctly we use the 32bit array }
  261. l:=pos shr 5;
  262. mask:=1 shl (pos mod 32);
  263. { do we allow the same twice }
  264. if (pconst32bitset(constset)^[l] and mask)<>0 then
  265. Message(parser_e_illegal_set_expr);
  266. pconst32bitset(constset)^[l]:=pconst32bitset(constset)^[l] or mask;
  267. {$else}
  268. include(constset^,pos);
  269. {$endif}
  270. end;
  271. var
  272. l : Longint;
  273. lr,hr : TConstExprInt;
  274. hp : tarrayconstructornode;
  275. begin
  276. if p.nodetype<>arrayconstructorn then
  277. internalerror(200205105);
  278. new(constset);
  279. {$ifdef oldset}
  280. FillChar(constset^,sizeof(constset^),0);
  281. {$else}
  282. constset^:=[];
  283. {$endif}
  284. htype.reset;
  285. constsetlo:=0;
  286. constsethi:=0;
  287. constp:=csetconstnode.create(nil,htype);
  288. constp.value_set:=constset;
  289. buildp:=constp;
  290. hp:=tarrayconstructornode(p);
  291. if assigned(hp.left) then
  292. begin
  293. while assigned(hp) do
  294. begin
  295. p4:=nil; { will contain the tree to create the set }
  296. {split a range into p2 and p3 }
  297. if hp.left.nodetype=arrayconstructorrangen then
  298. begin
  299. p2:=tarrayconstructorrangenode(hp.left).left;
  300. p3:=tarrayconstructorrangenode(hp.left).right;
  301. tarrayconstructorrangenode(hp.left).left:=nil;
  302. tarrayconstructorrangenode(hp.left).right:=nil;
  303. end
  304. else
  305. begin
  306. p2:=hp.left;
  307. hp.left:=nil;
  308. p3:=nil;
  309. end;
  310. resulttypepass(p2);
  311. if assigned(p3) then
  312. resulttypepass(p3);
  313. if codegenerror then
  314. break;
  315. case p2.resulttype.def.deftype of
  316. enumdef,
  317. orddef:
  318. begin
  319. getrange(p2.resulttype.def,lr,hr);
  320. if assigned(p3) then
  321. begin
  322. { this isn't good, you'll get problems with
  323. type t010 = 0..10;
  324. ts = set of t010;
  325. var s : ts;b : t010
  326. begin s:=[1,2,b]; end.
  327. if is_integer(p3^.resulttype.def) then
  328. begin
  329. inserttypeconv(p3,u8bitdef);
  330. end;
  331. }
  332. if assigned(htype.def) and not(equal_defs(htype.def,p3.resulttype.def)) then
  333. begin
  334. aktfilepos:=p3.fileinfo;
  335. CGMessage(type_e_typeconflict_in_set);
  336. end
  337. else
  338. begin
  339. if (p2.nodetype=ordconstn) and (p3.nodetype=ordconstn) then
  340. begin
  341. if not(is_integer(p3.resulttype.def)) then
  342. htype:=p3.resulttype
  343. else
  344. begin
  345. inserttypeconv(p3,u8bittype);
  346. inserttypeconv(p2,u8bittype);
  347. end;
  348. for l:=tordconstnode(p2).value to tordconstnode(p3).value do
  349. do_set(l);
  350. p2.free;
  351. p3.free;
  352. end
  353. else
  354. begin
  355. update_constsethi(p2.resulttype);
  356. inserttypeconv(p2,htype);
  357. update_constsethi(p3.resulttype);
  358. inserttypeconv(p3,htype);
  359. if assigned(htype.def) then
  360. inserttypeconv(p3,htype)
  361. else
  362. inserttypeconv(p3,u8bittype);
  363. p4:=csetelementnode.create(p2,p3);
  364. end;
  365. end;
  366. end
  367. else
  368. begin
  369. { Single value }
  370. if p2.nodetype=ordconstn then
  371. begin
  372. if not(is_integer(p2.resulttype.def)) then
  373. update_constsethi(p2.resulttype)
  374. else
  375. inserttypeconv(p2,u8bittype);
  376. do_set(tordconstnode(p2).value);
  377. p2.free;
  378. end
  379. else
  380. begin
  381. update_constsethi(p2.resulttype);
  382. if assigned(htype.def) then
  383. inserttypeconv(p2,htype)
  384. else
  385. inserttypeconv(p2,u8bittype);
  386. p4:=csetelementnode.create(p2,nil);
  387. end;
  388. end;
  389. end;
  390. stringdef :
  391. begin
  392. { if we've already set elements which are constants }
  393. { throw an error }
  394. if ((htype.def=nil) and assigned(buildp)) or
  395. not(is_char(htype.def)) then
  396. CGMessage(type_e_typeconflict_in_set)
  397. else
  398. for l:=1 to length(pstring(tstringconstnode(p2).value_str)^) do
  399. do_set(ord(pstring(tstringconstnode(p2).value_str)^[l]));
  400. if htype.def=nil then
  401. htype:=cchartype;
  402. p2.free;
  403. end;
  404. else
  405. CGMessage(type_e_ordinal_expr_expected);
  406. end;
  407. { insert the set creation tree }
  408. if assigned(p4) then
  409. buildp:=caddnode.create(addn,buildp,p4);
  410. { load next and dispose current node }
  411. p2:=hp;
  412. hp:=tarrayconstructornode(tarrayconstructornode(p2).right);
  413. tarrayconstructornode(p2).right:=nil;
  414. p2.free;
  415. end;
  416. if (htype.def=nil) then
  417. htype:=u8bittype;
  418. end
  419. else
  420. begin
  421. { empty set [], only remove node }
  422. p.free;
  423. end;
  424. { set the initial set type }
  425. constp.resulttype.setdef(tsetdef.create(htype,constsethi));
  426. { determine the resulttype for the tree }
  427. resulttypepass(buildp);
  428. { set the new tree }
  429. p:=buildp;
  430. end;
  431. {*****************************************************************************
  432. TTYPECONVNODE
  433. *****************************************************************************}
  434. constructor ttypeconvnode.create(node : tnode;const t:ttype);
  435. begin
  436. inherited create(typeconvn,node);
  437. convtype:=tc_not_possible;
  438. totype:=t;
  439. if t.def=nil then
  440. internalerror(200103281);
  441. set_file_line(node);
  442. end;
  443. constructor ttypeconvnode.create_explicit(node : tnode;const t:ttype);
  444. begin
  445. self.create(node,t);
  446. toggleflag(nf_explizit);
  447. end;
  448. constructor ttypeconvnode.ppuload(t:tnodetype;ppufile:tcompilerppufile);
  449. begin
  450. inherited ppuload(t,ppufile);
  451. ppufile.gettype(totype);
  452. convtype:=tconverttype(ppufile.getbyte);
  453. end;
  454. procedure ttypeconvnode.ppuwrite(ppufile:tcompilerppufile);
  455. begin
  456. inherited ppuwrite(ppufile);
  457. ppufile.puttype(totype);
  458. ppufile.putbyte(byte(convtype));
  459. end;
  460. procedure ttypeconvnode.derefimpl;
  461. begin
  462. inherited derefimpl;
  463. totype.resolve;
  464. end;
  465. function ttypeconvnode.getcopy : tnode;
  466. var
  467. n : ttypeconvnode;
  468. begin
  469. n:=ttypeconvnode(inherited getcopy);
  470. n.convtype:=convtype;
  471. getcopy:=n;
  472. end;
  473. function ttypeconvnode.resulttype_cord_to_pointer : tnode;
  474. var
  475. t : tnode;
  476. begin
  477. result:=nil;
  478. if left.nodetype=ordconstn then
  479. begin
  480. { check if we have a valid pointer constant (JM) }
  481. if (sizeof(pointer) > sizeof(TConstPtrUInt)) then
  482. if (sizeof(TConstPtrUInt) = 4) then
  483. begin
  484. if (tordconstnode(left).value < low(longint)) or
  485. (tordconstnode(left).value > high(cardinal)) then
  486. CGMessage(parser_e_range_check_error);
  487. end
  488. else if (sizeof(TConstPtrUInt) = 8) then
  489. begin
  490. if (tordconstnode(left).value < low(int64)) or
  491. (tordconstnode(left).value > high(qword)) then
  492. CGMessage(parser_e_range_check_error);
  493. end
  494. else
  495. internalerror(2001020801);
  496. t:=cpointerconstnode.create(TConstPtrUInt(tordconstnode(left).value),resulttype);
  497. result:=t;
  498. end
  499. else
  500. internalerror(200104023);
  501. end;
  502. function ttypeconvnode.resulttype_chararray_to_string : tnode;
  503. begin
  504. result := ccallnode.createinternres(
  505. 'fpc_chararray_to_'+tstringdef(resulttype.def).stringtypname,
  506. ccallparanode.create(left,nil),resulttype);
  507. left := nil;
  508. end;
  509. function ttypeconvnode.resulttype_string_to_chararray : tnode;
  510. var
  511. arrsize: longint;
  512. begin
  513. with tarraydef(resulttype.def) do
  514. begin
  515. if highrange<lowrange then
  516. internalerror(75432653);
  517. arrsize := highrange-lowrange+1;
  518. end;
  519. if (left.nodetype = stringconstn) and
  520. { left.length+1 since there's always a terminating #0 character (JM) }
  521. (tstringconstnode(left).len+1 >= arrsize) and
  522. (tstringdef(left.resulttype.def).string_typ=st_shortstring) then
  523. begin
  524. { handled separately }
  525. result := nil;
  526. exit;
  527. end;
  528. result := ccallnode.createinternres(
  529. 'fpc_'+tstringdef(left.resulttype.def).stringtypname+
  530. '_to_chararray',ccallparanode.create(left,ccallparanode.create(
  531. cordconstnode.create(arrsize,s32bittype,true),nil)),resulttype);
  532. left := nil;
  533. end;
  534. function ttypeconvnode.resulttype_string_to_string : tnode;
  535. var
  536. procname: string[31];
  537. stringpara : tcallparanode;
  538. pw : pcompilerwidestring;
  539. pc : pchar;
  540. begin
  541. result:=nil;
  542. if left.nodetype=stringconstn then
  543. begin
  544. { convert ascii 2 unicode }
  545. if (tstringdef(resulttype.def).string_typ=st_widestring) and
  546. (tstringconstnode(left).st_type in [st_ansistring,st_shortstring,st_longstring]) then
  547. begin
  548. initwidestring(pw);
  549. ascii2unicode(tstringconstnode(left).value_str,tstringconstnode(left).len,pw);
  550. ansistringdispose(tstringconstnode(left).value_str,tstringconstnode(left).len);
  551. pcompilerwidestring(tstringconstnode(left).value_str):=pw;
  552. end
  553. else
  554. { convert unicode 2 ascii }
  555. if (tstringconstnode(left).st_type=st_widestring) and
  556. (tstringdef(resulttype.def).string_typ in [st_ansistring,st_shortstring,st_longstring]) then
  557. begin
  558. pw:=pcompilerwidestring(tstringconstnode(left).value_str);
  559. getmem(pc,getlengthwidestring(pw)+1);
  560. unicode2ascii(pw,pc);
  561. donewidestring(pw);
  562. tstringconstnode(left).value_str:=pc;
  563. end;
  564. tstringconstnode(left).st_type:=tstringdef(resulttype.def).string_typ;
  565. tstringconstnode(left).resulttype:=resulttype;
  566. result:=left;
  567. left:=nil;
  568. end
  569. else
  570. begin
  571. { get the correct procedure name }
  572. procname := 'fpc_'+tstringdef(left.resulttype.def).stringtypname+
  573. '_to_'+tstringdef(resulttype.def).stringtypname;
  574. { create parameter (and remove left node from typeconvnode }
  575. { since it's reused as parameter) }
  576. stringpara := ccallparanode.create(left,nil);
  577. left := nil;
  578. { when converting to shortstrings, we have to pass high(destination) too }
  579. if (tstringdef(resulttype.def).string_typ = st_shortstring) then
  580. stringpara.right := ccallparanode.create(cinlinenode.create(
  581. in_high_x,false,self.getcopy),nil);
  582. { and create the callnode }
  583. result := ccallnode.createinternres(procname,stringpara,resulttype);
  584. end;
  585. end;
  586. function ttypeconvnode.resulttype_char_to_string : tnode;
  587. var
  588. procname: string[31];
  589. para : tcallparanode;
  590. hp : tstringconstnode;
  591. ws : pcompilerwidestring;
  592. begin
  593. result:=nil;
  594. if left.nodetype=ordconstn then
  595. begin
  596. if tstringdef(resulttype.def).string_typ=st_widestring then
  597. begin
  598. initwidestring(ws);
  599. concatwidestringchar(ws,tcompilerwidechar(chr(tordconstnode(left).value)));
  600. hp:=cstringconstnode.createwstr(ws);
  601. donewidestring(ws);
  602. end
  603. else
  604. hp:=cstringconstnode.createstr(chr(tordconstnode(left).value),tstringdef(resulttype.def).string_typ);
  605. result:=hp;
  606. end
  607. else
  608. { shortstrings are handled 'inline' }
  609. if tstringdef(resulttype.def).string_typ <> st_shortstring then
  610. begin
  611. { create the parameter }
  612. para := ccallparanode.create(left,nil);
  613. left := nil;
  614. { and the procname }
  615. procname := 'fpc_char_to_' +tstringdef(resulttype.def).stringtypname;
  616. { and finally the call }
  617. result := ccallnode.createinternres(procname,para,resulttype);
  618. end
  619. else
  620. begin
  621. { create word(byte(char) shl 8 or 1) for litte endian machines }
  622. { and word(byte(char) or 256) for big endian machines }
  623. left := ctypeconvnode.create(left,u8bittype);
  624. left.toggleflag(nf_explizit);
  625. if (target_info.endian = endian_little) then
  626. left := caddnode.create(orn,
  627. cshlshrnode.create(shln,left,cordconstnode.create(8,s32bittype,false)),
  628. cordconstnode.create(1,s32bittype,false))
  629. else
  630. left := caddnode.create(orn,left,
  631. cordconstnode.create(1 shl 8,s32bittype,false));
  632. left := ctypeconvnode.create(left,u16bittype);
  633. left.toggleflag(nf_explizit);
  634. resulttypepass(left);
  635. end;
  636. end;
  637. function ttypeconvnode.resulttype_char_to_chararray : tnode;
  638. begin
  639. if resulttype.def.size <> 1 then
  640. begin
  641. { convert first to string, then to chararray }
  642. inserttypeconv(left,cshortstringtype);
  643. inserttypeconv(left,resulttype);
  644. result:=left;
  645. left := nil;
  646. exit;
  647. end;
  648. result := nil;
  649. end;
  650. function ttypeconvnode.resulttype_char_to_char : tnode;
  651. var
  652. hp : tordconstnode;
  653. begin
  654. result:=nil;
  655. if left.nodetype=ordconstn then
  656. begin
  657. if (torddef(resulttype.def).typ=uchar) and
  658. (torddef(left.resulttype.def).typ=uwidechar) then
  659. begin
  660. hp:=cordconstnode.create(
  661. ord(unicode2asciichar(tcompilerwidechar(tordconstnode(left).value))),
  662. cchartype,true);
  663. result:=hp;
  664. end
  665. else if (torddef(resulttype.def).typ=uwidechar) and
  666. (torddef(left.resulttype.def).typ=uchar) then
  667. begin
  668. hp:=cordconstnode.create(
  669. asciichar2unicode(chr(tordconstnode(left).value)),
  670. cwidechartype,true);
  671. result:=hp;
  672. end
  673. else
  674. internalerror(200105131);
  675. exit;
  676. end;
  677. end;
  678. function ttypeconvnode.resulttype_int_to_real : tnode;
  679. var
  680. t : trealconstnode;
  681. begin
  682. result:=nil;
  683. if left.nodetype=ordconstn then
  684. begin
  685. t:=crealconstnode.create(tordconstnode(left).value,resulttype);
  686. result:=t;
  687. end;
  688. end;
  689. function ttypeconvnode.resulttype_real_to_real : tnode;
  690. var
  691. t : tnode;
  692. begin
  693. result:=nil;
  694. if is_currency(left.resulttype.def) and not(is_currency(resulttype.def)) then
  695. begin
  696. left:=caddnode.create(slashn,left,crealconstnode.create(10000.0,left.resulttype));
  697. resulttypepass(left);
  698. end
  699. else
  700. if is_currency(resulttype.def) and not(is_currency(left.resulttype.def)) then
  701. begin
  702. left:=caddnode.create(muln,left,crealconstnode.create(10000.0,left.resulttype));
  703. resulttypepass(left);
  704. end;
  705. if left.nodetype=realconstn then
  706. begin
  707. t:=crealconstnode.create(trealconstnode(left).value_real,resulttype);
  708. result:=t;
  709. end;
  710. end;
  711. function ttypeconvnode.resulttype_cchar_to_pchar : tnode;
  712. begin
  713. result:=nil;
  714. if is_pwidechar(resulttype.def) then
  715. inserttypeconv(left,cwidestringtype)
  716. else
  717. inserttypeconv(left,cshortstringtype);
  718. { evaluate again, reset resulttype so the convert_typ
  719. will be calculated again and cstring_to_pchar will
  720. be used for futher conversion }
  721. result:=det_resulttype;
  722. end;
  723. function ttypeconvnode.resulttype_cstring_to_pchar : tnode;
  724. begin
  725. result:=nil;
  726. if is_pwidechar(resulttype.def) then
  727. inserttypeconv(left,cwidestringtype);
  728. end;
  729. function ttypeconvnode.resulttype_arrayconstructor_to_set : tnode;
  730. var
  731. hp : tnode;
  732. begin
  733. result:=nil;
  734. if left.nodetype<>arrayconstructorn then
  735. internalerror(5546);
  736. { remove typeconv node }
  737. hp:=left;
  738. left:=nil;
  739. { create a set constructor tree }
  740. arrayconstructor_to_set(hp);
  741. result:=hp;
  742. end;
  743. function ttypeconvnode.resulttype_pchar_to_string : tnode;
  744. begin
  745. result := ccallnode.createinternres(
  746. 'fpc_pchar_to_'+tstringdef(resulttype.def).stringtypname,
  747. ccallparanode.create(left,nil),resulttype);
  748. left := nil;
  749. end;
  750. function ttypeconvnode.resulttype_interface_to_guid : tnode;
  751. begin
  752. if assigned(tobjectdef(left.resulttype.def).iidguid) then
  753. result:=cguidconstnode.create(tobjectdef(left.resulttype.def).iidguid^);
  754. end;
  755. function ttypeconvnode.resulttype_dynarray_to_openarray : tnode;
  756. begin
  757. { a dynamic array is a pointer to an array, so to convert it to }
  758. { an open array, we have to dereference it (JM) }
  759. result := ctypeconvnode.create(left,voidpointertype);
  760. { left is reused }
  761. left := nil;
  762. result.toggleflag(nf_explizit);
  763. result := cderefnode.create(result);
  764. result.resulttype := resulttype;
  765. end;
  766. function ttypeconvnode.resulttype_pwchar_to_string : tnode;
  767. begin
  768. result := ccallnode.createinternres(
  769. 'fpc_pwidechar_to_'+tstringdef(resulttype.def).stringtypname,
  770. ccallparanode.create(left,nil),resulttype);
  771. left := nil;
  772. end;
  773. function ttypeconvnode.resulttype_call_helper(c : tconverttype) : tnode;
  774. {$ifdef fpc}
  775. const
  776. resulttypeconvert : array[tconverttype] of pointer = (
  777. {equal} nil,
  778. {not_possible} nil,
  779. { string_2_string } @ttypeconvnode.resulttype_string_to_string,
  780. { char_2_string } @ttypeconvnode.resulttype_char_to_string,
  781. { char_2_chararray } @ttypeconvnode.resulttype_char_to_chararray,
  782. { pchar_2_string } @ttypeconvnode.resulttype_pchar_to_string,
  783. { cchar_2_pchar } @ttypeconvnode.resulttype_cchar_to_pchar,
  784. { cstring_2_pchar } @ttypeconvnode.resulttype_cstring_to_pchar,
  785. { ansistring_2_pchar } nil,
  786. { string_2_chararray } @ttypeconvnode.resulttype_string_to_chararray,
  787. { chararray_2_string } @ttypeconvnode.resulttype_chararray_to_string,
  788. { array_2_pointer } nil,
  789. { pointer_2_array } nil,
  790. { int_2_int } nil,
  791. { int_2_bool } nil,
  792. { bool_2_bool } nil,
  793. { bool_2_int } nil,
  794. { real_2_real } @ttypeconvnode.resulttype_real_to_real,
  795. { int_2_real } @ttypeconvnode.resulttype_int_to_real,
  796. { proc_2_procvar } nil,
  797. { arrayconstructor_2_set } @ttypeconvnode.resulttype_arrayconstructor_to_set,
  798. { load_smallset } nil,
  799. { cord_2_pointer } @ttypeconvnode.resulttype_cord_to_pointer,
  800. { intf_2_string } nil,
  801. { intf_2_guid } @ttypeconvnode.resulttype_interface_to_guid,
  802. { class_2_intf } nil,
  803. { char_2_char } @ttypeconvnode.resulttype_char_to_char,
  804. { normal_2_smallset} nil,
  805. { dynarray_2_openarray} @resulttype_dynarray_to_openarray,
  806. { pwchar_2_string} @resulttype_pwchar_to_string
  807. );
  808. type
  809. tprocedureofobject = function : tnode of object;
  810. var
  811. r : packed record
  812. proc : pointer;
  813. obj : pointer;
  814. end;
  815. begin
  816. result:=nil;
  817. { this is a little bit dirty but it works }
  818. { and should be quite portable too }
  819. r.proc:=resulttypeconvert[c];
  820. r.obj:=self;
  821. if assigned(r.proc) then
  822. result:=tprocedureofobject(r){$ifdef FPC}();{$endif FPC}
  823. end;
  824. {$else}
  825. begin
  826. case c of
  827. tc_string_2_string: resulttype_string_to_string;
  828. tc_char_2_string : resulttype_char_to_string;
  829. tc_char_2_chararray: resulttype_char_to_chararray;
  830. tc_pchar_2_string : resulttype_pchar_to_string;
  831. tc_cchar_2_pchar : resulttype_cchar_to_pchar;
  832. tc_cstring_2_pchar : resulttype_cstring_to_pchar;
  833. tc_string_2_chararray : resulttype_string_to_chararray;
  834. tc_chararray_2_string : resulttype_chararray_to_string;
  835. tc_real_2_real : resulttype_real_to_real;
  836. tc_int_2_real : resulttype_int_to_real;
  837. tc_arrayconstructor_2_set : resulttype_arrayconstructor_to_set;
  838. tc_cord_2_pointer : resulttype_cord_to_pointer;
  839. tc_intf_2_guid : resulttype_interface_to_guid;
  840. tc_char_2_char : resulttype_char_to_char;
  841. tc_dynarray_2_openarray : resulttype_dynarray_to_openarray;
  842. tc_pwchar_2_string : resulttype_pwchar_to_string;
  843. end;
  844. end;
  845. {$Endif fpc}
  846. function ttypeconvnode.det_resulttype:tnode;
  847. var
  848. hp : tnode;
  849. currprocdef,
  850. aprocdef : tprocdef;
  851. eq : tequaltype;
  852. begin
  853. result:=nil;
  854. resulttype:=totype;
  855. resulttypepass(left);
  856. if codegenerror then
  857. exit;
  858. eq:=compare_defs_ext(left.resulttype.def,resulttype.def,left.nodetype,
  859. nf_explizit in flags,true,convtype,aprocdef);
  860. case eq of
  861. te_exact,
  862. te_equal :
  863. begin
  864. { because is_equal only checks the basetype for sets we need to
  865. check here if we are loading a smallset into a normalset }
  866. if (resulttype.def.deftype=setdef) and
  867. (left.resulttype.def.deftype=setdef) and
  868. ((tsetdef(resulttype.def).settype = smallset) xor
  869. (tsetdef(left.resulttype.def).settype = smallset)) then
  870. begin
  871. { constant sets can be converted by changing the type only }
  872. if (left.nodetype=setconstn) then
  873. begin
  874. tsetdef(left.resulttype.def).changesettype(tsetdef(resulttype.def).settype);
  875. result:=left;
  876. left:=nil;
  877. exit;
  878. end;
  879. if (tsetdef(resulttype.def).settype <> smallset) then
  880. convtype:=tc_load_smallset
  881. else
  882. convtype := tc_normal_2_smallset;
  883. exit;
  884. end
  885. else
  886. begin
  887. left.resulttype:=resulttype;
  888. result:=left;
  889. left:=nil;
  890. exit;
  891. end;
  892. end;
  893. te_convert_l1,
  894. te_convert_l2 :
  895. begin
  896. { nothing to do }
  897. end;
  898. te_convert_operator :
  899. begin
  900. procinfo.flags:=procinfo.flags or pi_do_call;
  901. hp:=ccallnode.create(ccallparanode.create(left,nil),
  902. overloaded_operators[_assignment],nil,nil);
  903. { tell explicitly which def we must use !! (PM) }
  904. tcallnode(hp).procdefinition:=aprocdef;
  905. left:=nil;
  906. result:=hp;
  907. exit;
  908. end;
  909. te_incompatible :
  910. begin
  911. { Procedures have a resulttype.def of voiddef and functions of their
  912. own resulttype.def. They will therefore always be incompatible with
  913. a procvar. Because isconvertable cannot check for procedures we
  914. use an extra check for them.}
  915. if (m_tp_procvar in aktmodeswitches) then
  916. begin
  917. if (resulttype.def.deftype=procvardef) and
  918. (is_procsym_load(left) or is_procsym_call(left)) then
  919. begin
  920. if is_procsym_call(left) then
  921. begin
  922. currprocdef:=Tprocsym(Tcallnode(left).symtableprocentry).search_procdef_byprocvardef(Tprocvardef(resulttype.def));
  923. hp:=cloadnode.create_procvar(tprocsym(tcallnode(left).symtableprocentry),
  924. currprocdef,tcallnode(left).symtableproc);
  925. if (tcallnode(left).symtableprocentry.owner.symtabletype=objectsymtable) and
  926. assigned(tcallnode(left).methodpointer) then
  927. tloadnode(hp).set_mp(tcallnode(left).methodpointer.getcopy);
  928. resulttypepass(hp);
  929. left.free;
  930. left:=hp;
  931. aprocdef:=tprocdef(left.resulttype.def);
  932. end
  933. else
  934. begin
  935. if (left.nodetype<>addrn) then
  936. aprocdef:=tprocsym(tloadnode(left).symtableentry).first_procdef;
  937. end;
  938. convtype:=tc_proc_2_procvar;
  939. { Now check if the procedure we are going to assign to
  940. the procvar, is compatible with the procvar's type }
  941. if assigned(aprocdef) then
  942. begin
  943. if proc_to_procvar_equal(aprocdef,tprocvardef(resulttype.def))=te_incompatible then
  944. CGMessage2(type_e_incompatible_types,aprocdef.typename,resulttype.def.typename);
  945. end
  946. else
  947. CGMessage2(type_e_incompatible_types,left.resulttype.def.typename,resulttype.def.typename);
  948. exit;
  949. end;
  950. end;
  951. { Handle explicit type conversions }
  952. if nf_explizit in flags then
  953. begin
  954. { do common tc_equal cast }
  955. convtype:=tc_equal;
  956. { check if the result could be in a register }
  957. if not(tstoreddef(resulttype.def).is_intregable) and
  958. not(tstoreddef(resulttype.def).is_fpuregable) then
  959. make_not_regable(left);
  960. { class to class or object to object, with checkobject support }
  961. if (resulttype.def.deftype=objectdef) and
  962. (left.resulttype.def.deftype=objectdef) then
  963. begin
  964. if (cs_check_object in aktlocalswitches) then
  965. begin
  966. if is_class_or_interface(resulttype.def) then
  967. begin
  968. { we can translate the typeconvnode to 'as' when
  969. typecasting to a class or interface }
  970. hp:=casnode.create(left,cloadvmtnode.create(ctypenode.create(resulttype)));
  971. left:=nil;
  972. result:=hp;
  973. exit;
  974. end;
  975. end
  976. else
  977. begin
  978. { check if the types are related }
  979. if (not(tobjectdef(left.resulttype.def).is_related(tobjectdef(resulttype.def)))) and
  980. (not(tobjectdef(resulttype.def).is_related(tobjectdef(left.resulttype.def)))) then
  981. CGMessage2(type_w_classes_not_related,left.resulttype.def.typename,resulttype.def.typename);
  982. end;
  983. end
  984. { only if the same size or formal def }
  985. { why do we allow typecasting of voiddef ?? (PM) }
  986. else
  987. begin
  988. if not(
  989. (left.resulttype.def.deftype=formaldef) or
  990. (not(is_open_array(left.resulttype.def)) and
  991. (left.resulttype.def.size=resulttype.def.size)) or
  992. (is_void(left.resulttype.def) and
  993. (left.nodetype=derefn))
  994. ) then
  995. CGMessage(cg_e_illegal_type_conversion);
  996. if ((left.resulttype.def.deftype=orddef) and
  997. (resulttype.def.deftype=pointerdef)) or
  998. ((resulttype.def.deftype=orddef) and
  999. (left.resulttype.def.deftype=pointerdef)) then
  1000. CGMessage(cg_d_pointer_to_longint_conv_not_portable);
  1001. end;
  1002. { the conversion into a strutured type is only }
  1003. { possible, if the source is not a register }
  1004. if (
  1005. (resulttype.def.deftype in [recorddef,stringdef,arraydef]) or
  1006. ((resulttype.def.deftype=objectdef) and
  1007. not(is_class(resulttype.def)))
  1008. ) and
  1009. (left.location.loc in [LOC_REGISTER,LOC_CREGISTER]) then
  1010. CGMessage(cg_e_illegal_type_conversion);
  1011. end
  1012. else
  1013. CGMessage2(type_e_incompatible_types,left.resulttype.def.typename,resulttype.def.typename);
  1014. end;
  1015. else
  1016. internalerror(200211231);
  1017. end;
  1018. { Constant folding and other node transitions to
  1019. remove the typeconv node }
  1020. case left.nodetype of
  1021. loadn :
  1022. begin
  1023. { tp7 procvar support, when right is not a procvardef and we got a
  1024. loadn of a procvar then convert to a calln, the check for the
  1025. result is already done in is_convertible, also no conflict with
  1026. @procvar is here because that has an extra addrn }
  1027. if (m_tp_procvar in aktmodeswitches) and
  1028. (resulttype.def.deftype<>procvardef) and
  1029. (left.resulttype.def.deftype=procvardef) then
  1030. begin
  1031. hp:=ccallnode.create(nil,nil,nil,nil);
  1032. tcallnode(hp).set_procvar(left);
  1033. resulttypepass(hp);
  1034. left:=hp;
  1035. end;
  1036. end;
  1037. niln :
  1038. begin
  1039. { nil to ordinal node }
  1040. if (resulttype.def.deftype=orddef) then
  1041. begin
  1042. hp:=cordconstnode.create(0,resulttype,true);
  1043. result:=hp;
  1044. exit;
  1045. end
  1046. else
  1047. { fold nil to any pointer type }
  1048. if (resulttype.def.deftype=pointerdef) then
  1049. begin
  1050. hp:=cnilnode.create;
  1051. hp.resulttype:=resulttype;
  1052. result:=hp;
  1053. exit;
  1054. end
  1055. else
  1056. { remove typeconv after niln, but not when the result is a
  1057. methodpointer. The typeconv of the methodpointer will then
  1058. take care of updateing size of niln to OS_64 }
  1059. if not((resulttype.def.deftype=procvardef) and
  1060. (po_methodpointer in tprocvardef(resulttype.def).procoptions)) then
  1061. begin
  1062. left.resulttype:=resulttype;
  1063. result:=left;
  1064. left:=nil;
  1065. exit;
  1066. end;
  1067. end;
  1068. ordconstn :
  1069. begin
  1070. { ordinal contants can be directly converted }
  1071. { but not char to char because it is a widechar to char or via versa }
  1072. { which needs extra code to do the code page transistion }
  1073. if is_ordinal(resulttype.def) and
  1074. not(convtype=tc_char_2_char) then
  1075. begin
  1076. { replace the resulttype and recheck the range }
  1077. left.resulttype:=resulttype;
  1078. testrange(left.resulttype.def,tordconstnode(left).value,(nf_explizit in flags));
  1079. result:=left;
  1080. left:=nil;
  1081. exit;
  1082. end;
  1083. end;
  1084. pointerconstn :
  1085. begin
  1086. { pointerconstn to any pointer is folded too }
  1087. if (resulttype.def.deftype=pointerdef) then
  1088. begin
  1089. left.resulttype:=resulttype;
  1090. result:=left;
  1091. left:=nil;
  1092. exit;
  1093. end
  1094. { constant pointer to ordinal }
  1095. else if is_ordinal(resulttype.def) then
  1096. begin
  1097. hp:=cordconstnode.create(tpointerconstnode(left).value,
  1098. resulttype,true);
  1099. result:=hp;
  1100. exit;
  1101. end;
  1102. end;
  1103. end;
  1104. { now call the resulttype helper to do constant folding }
  1105. result:=resulttype_call_helper(convtype);
  1106. end;
  1107. {$ifdef var_notification}
  1108. procedure Ttypeconvnode.mark_write;
  1109. begin
  1110. left.mark_write;
  1111. end;
  1112. {$endif}
  1113. function ttypeconvnode.first_cord_to_pointer : tnode;
  1114. begin
  1115. result:=nil;
  1116. internalerror(200104043);
  1117. end;
  1118. function ttypeconvnode.first_int_to_int : tnode;
  1119. begin
  1120. first_int_to_int:=nil;
  1121. if (left.location.loc<>LOC_REGISTER) and
  1122. (resulttype.def.size>left.resulttype.def.size) then
  1123. location.loc:=LOC_REGISTER;
  1124. if is_64bitint(resulttype.def) then
  1125. registers32:=max(registers32,2)
  1126. else
  1127. registers32:=max(registers32,1);
  1128. end;
  1129. function ttypeconvnode.first_cstring_to_pchar : tnode;
  1130. begin
  1131. first_cstring_to_pchar:=nil;
  1132. registers32:=1;
  1133. location.loc:=LOC_REGISTER;
  1134. end;
  1135. function ttypeconvnode.first_string_to_chararray : tnode;
  1136. begin
  1137. first_string_to_chararray:=nil;
  1138. registers32:=1;
  1139. location.loc:=LOC_REGISTER;
  1140. end;
  1141. function ttypeconvnode.first_char_to_string : tnode;
  1142. begin
  1143. first_char_to_string:=nil;
  1144. location.loc:=LOC_CREFERENCE;
  1145. end;
  1146. function ttypeconvnode.first_nothing : tnode;
  1147. begin
  1148. first_nothing:=nil;
  1149. end;
  1150. function ttypeconvnode.first_array_to_pointer : tnode;
  1151. begin
  1152. first_array_to_pointer:=nil;
  1153. if registers32<1 then
  1154. registers32:=1;
  1155. location.loc:=LOC_REGISTER;
  1156. end;
  1157. function ttypeconvnode.first_int_to_real: tnode;
  1158. var
  1159. fname: string[19];
  1160. typname : string[12];
  1161. begin
  1162. { Get the type name }
  1163. { Normally the typename should be one of the following:
  1164. single, double - carl
  1165. }
  1166. typname := lower(pbestrealtype^.def.gettypename);
  1167. { converting a 64bit integer to a float requires a helper }
  1168. if is_64bitint(left.resulttype.def) then
  1169. begin
  1170. if is_signed(left.resulttype.def) then
  1171. fname := 'fpc_int64_to_'+typname
  1172. else
  1173. fname := 'fpc_qword_to_'+typname;
  1174. result := ccallnode.createintern(fname,ccallparanode.create(
  1175. left,nil));
  1176. left:=nil;
  1177. firstpass(result);
  1178. exit;
  1179. end
  1180. else
  1181. { other integers are supposed to be 32 bit }
  1182. begin
  1183. if is_signed(left.resulttype.def) then
  1184. fname := 'fpc_longint_to_'+typname
  1185. else
  1186. fname := 'fpc_longword_to_'+typname;
  1187. result := ccallnode.createintern(fname,ccallparanode.create(
  1188. left,nil));
  1189. left:=nil;
  1190. firstpass(result);
  1191. exit;
  1192. end;
  1193. end;
  1194. function ttypeconvnode.first_real_to_real : tnode;
  1195. begin
  1196. first_real_to_real:=nil;
  1197. { comp isn't a floating type }
  1198. {$ifdef i386}
  1199. if (tfloatdef(resulttype.def).typ=s64comp) and
  1200. (tfloatdef(left.resulttype.def).typ<>s64comp) and
  1201. not (nf_explizit in flags) then
  1202. CGMessage(type_w_convert_real_2_comp);
  1203. {$endif}
  1204. if registersfpu<1 then
  1205. registersfpu:=1;
  1206. location.loc:=LOC_FPUREGISTER;
  1207. end;
  1208. function ttypeconvnode.first_pointer_to_array : tnode;
  1209. begin
  1210. first_pointer_to_array:=nil;
  1211. if registers32<1 then
  1212. registers32:=1;
  1213. location.loc:=LOC_REFERENCE;
  1214. end;
  1215. function ttypeconvnode.first_cchar_to_pchar : tnode;
  1216. begin
  1217. first_cchar_to_pchar:=nil;
  1218. internalerror(200104021);
  1219. end;
  1220. function ttypeconvnode.first_bool_to_int : tnode;
  1221. begin
  1222. first_bool_to_int:=nil;
  1223. { byte(boolean) or word(wordbool) or longint(longbool) must
  1224. be accepted for var parameters }
  1225. if (nf_explizit in flags) and
  1226. (left.resulttype.def.size=resulttype.def.size) and
  1227. (left.location.loc in [LOC_REFERENCE,LOC_CREFERENCE,LOC_CREGISTER]) then
  1228. exit;
  1229. { when converting to 64bit, first convert to a 32bit int and then }
  1230. { convert to a 64bit int (only necessary for 32bit processors) (JM) }
  1231. if resulttype.def.size > sizeof(aword) then
  1232. begin
  1233. result := ctypeconvnode.create(left,u32bittype);
  1234. result.toggleflag(nf_explizit);
  1235. result := ctypeconvnode.create(result,resulttype);
  1236. left := nil;
  1237. firstpass(result);
  1238. exit;
  1239. end;
  1240. location.loc:=LOC_REGISTER;
  1241. if registers32<1 then
  1242. registers32:=1;
  1243. end;
  1244. function ttypeconvnode.first_int_to_bool : tnode;
  1245. begin
  1246. first_int_to_bool:=nil;
  1247. { byte(boolean) or word(wordbool) or longint(longbool) must
  1248. be accepted for var parameters }
  1249. if (nf_explizit in flags) and
  1250. (left.resulttype.def.size=resulttype.def.size) and
  1251. (left.location.loc in [LOC_REFERENCE,LOC_CREFERENCE,LOC_CREGISTER]) then
  1252. exit;
  1253. location.loc:=LOC_REGISTER;
  1254. { need if bool to bool !!
  1255. not very nice !!
  1256. insertypeconv(left,s32bittype);
  1257. left.explizit:=true;
  1258. firstpass(left); }
  1259. if registers32<1 then
  1260. registers32:=1;
  1261. end;
  1262. function ttypeconvnode.first_bool_to_bool : tnode;
  1263. begin
  1264. first_bool_to_bool:=nil;
  1265. location.loc:=LOC_REGISTER;
  1266. if registers32<1 then
  1267. registers32:=1;
  1268. end;
  1269. function ttypeconvnode.first_char_to_char : tnode;
  1270. begin
  1271. first_char_to_char:=nil;
  1272. location.loc:=LOC_REGISTER;
  1273. if registers32<1 then
  1274. registers32:=1;
  1275. end;
  1276. function ttypeconvnode.first_proc_to_procvar : tnode;
  1277. begin
  1278. first_proc_to_procvar:=nil;
  1279. if (left.location.loc<>LOC_REFERENCE) then
  1280. CGMessage(cg_e_illegal_expression);
  1281. registers32:=left.registers32;
  1282. if registers32<1 then
  1283. registers32:=1;
  1284. location.loc:=LOC_REGISTER;
  1285. end;
  1286. function ttypeconvnode.first_load_smallset : tnode;
  1287. var
  1288. srsym: ttypesym;
  1289. p: tcallparanode;
  1290. begin
  1291. if not searchsystype('FPC_SMALL_SET',srsym) then
  1292. internalerror(200108313);
  1293. p := ccallparanode.create(left,nil);
  1294. { reused }
  1295. left := nil;
  1296. { convert parameter explicitely to fpc_small_set }
  1297. p.left := ctypeconvnode.create(p.left,srsym.restype);
  1298. p.left.toggleflag(nf_explizit);
  1299. { create call, adjust resulttype }
  1300. result :=
  1301. ccallnode.createinternres('fpc_set_load_small',p,resulttype);
  1302. firstpass(result);
  1303. end;
  1304. function ttypeconvnode.first_ansistring_to_pchar : tnode;
  1305. begin
  1306. first_ansistring_to_pchar:=nil;
  1307. location.loc:=LOC_REGISTER;
  1308. if registers32<1 then
  1309. registers32:=1;
  1310. end;
  1311. function ttypeconvnode.first_arrayconstructor_to_set : tnode;
  1312. begin
  1313. first_arrayconstructor_to_set:=nil;
  1314. internalerror(200104022);
  1315. end;
  1316. function ttypeconvnode.first_class_to_intf : tnode;
  1317. begin
  1318. first_class_to_intf:=nil;
  1319. location.loc:=LOC_REFERENCE;
  1320. if registers32<1 then
  1321. registers32:=1;
  1322. end;
  1323. function ttypeconvnode._first_int_to_int : tnode;
  1324. begin
  1325. result:=first_int_to_int;
  1326. end;
  1327. function ttypeconvnode._first_cstring_to_pchar : tnode;
  1328. begin
  1329. result:=first_cstring_to_pchar;
  1330. end;
  1331. function ttypeconvnode._first_string_to_chararray : tnode;
  1332. begin
  1333. result:=first_string_to_chararray;
  1334. end;
  1335. function ttypeconvnode._first_char_to_string : tnode;
  1336. begin
  1337. result:=first_char_to_string;
  1338. end;
  1339. function ttypeconvnode._first_nothing : tnode;
  1340. begin
  1341. result:=first_nothing;
  1342. end;
  1343. function ttypeconvnode._first_array_to_pointer : tnode;
  1344. begin
  1345. result:=first_array_to_pointer;
  1346. end;
  1347. function ttypeconvnode._first_int_to_real : tnode;
  1348. begin
  1349. result:=first_int_to_real;
  1350. end;
  1351. function ttypeconvnode._first_real_to_real : tnode;
  1352. begin
  1353. result:=first_real_to_real;
  1354. end;
  1355. function ttypeconvnode._first_pointer_to_array : tnode;
  1356. begin
  1357. result:=first_pointer_to_array;
  1358. end;
  1359. function ttypeconvnode._first_cchar_to_pchar : tnode;
  1360. begin
  1361. result:=first_cchar_to_pchar;
  1362. end;
  1363. function ttypeconvnode._first_bool_to_int : tnode;
  1364. begin
  1365. result:=first_bool_to_int;
  1366. end;
  1367. function ttypeconvnode._first_int_to_bool : tnode;
  1368. begin
  1369. result:=first_int_to_bool;
  1370. end;
  1371. function ttypeconvnode._first_bool_to_bool : tnode;
  1372. begin
  1373. result:=first_bool_to_bool;
  1374. end;
  1375. function ttypeconvnode._first_proc_to_procvar : tnode;
  1376. begin
  1377. result:=first_proc_to_procvar;
  1378. end;
  1379. function ttypeconvnode._first_load_smallset : tnode;
  1380. begin
  1381. result:=first_load_smallset;
  1382. end;
  1383. function ttypeconvnode._first_cord_to_pointer : tnode;
  1384. begin
  1385. result:=first_cord_to_pointer;
  1386. end;
  1387. function ttypeconvnode._first_ansistring_to_pchar : tnode;
  1388. begin
  1389. result:=first_ansistring_to_pchar;
  1390. end;
  1391. function ttypeconvnode._first_arrayconstructor_to_set : tnode;
  1392. begin
  1393. result:=first_arrayconstructor_to_set;
  1394. end;
  1395. function ttypeconvnode._first_class_to_intf : tnode;
  1396. begin
  1397. result:=first_class_to_intf;
  1398. end;
  1399. function ttypeconvnode._first_char_to_char : tnode;
  1400. begin
  1401. result:=first_char_to_char;
  1402. end;
  1403. function ttypeconvnode.first_call_helper(c : tconverttype) : tnode;
  1404. const
  1405. firstconvert : array[tconverttype] of pointer = (
  1406. @ttypeconvnode._first_nothing, {equal}
  1407. @ttypeconvnode._first_nothing, {not_possible}
  1408. nil, { removed in resulttype_string_to_string }
  1409. @ttypeconvnode._first_char_to_string,
  1410. @ttypeconvnode._first_nothing, { char_2_chararray, needs nothing extra }
  1411. nil, { removed in resulttype_chararray_to_string }
  1412. @ttypeconvnode._first_cchar_to_pchar,
  1413. @ttypeconvnode._first_cstring_to_pchar,
  1414. @ttypeconvnode._first_ansistring_to_pchar,
  1415. @ttypeconvnode._first_string_to_chararray,
  1416. nil, { removed in resulttype_chararray_to_string }
  1417. @ttypeconvnode._first_array_to_pointer,
  1418. @ttypeconvnode._first_pointer_to_array,
  1419. @ttypeconvnode._first_int_to_int,
  1420. @ttypeconvnode._first_int_to_bool,
  1421. @ttypeconvnode._first_bool_to_bool,
  1422. @ttypeconvnode._first_bool_to_int,
  1423. @ttypeconvnode._first_real_to_real,
  1424. @ttypeconvnode._first_int_to_real,
  1425. @ttypeconvnode._first_proc_to_procvar,
  1426. @ttypeconvnode._first_arrayconstructor_to_set,
  1427. @ttypeconvnode._first_load_smallset,
  1428. @ttypeconvnode._first_cord_to_pointer,
  1429. @ttypeconvnode._first_nothing,
  1430. @ttypeconvnode._first_nothing,
  1431. @ttypeconvnode._first_class_to_intf,
  1432. @ttypeconvnode._first_char_to_char,
  1433. @ttypeconvnode._first_nothing,
  1434. @ttypeconvnode._first_nothing,
  1435. nil
  1436. );
  1437. type
  1438. tprocedureofobject = function : tnode of object;
  1439. var
  1440. r : packed record
  1441. proc : pointer;
  1442. obj : pointer;
  1443. end;
  1444. begin
  1445. { this is a little bit dirty but it works }
  1446. { and should be quite portable too }
  1447. r.proc:=firstconvert[c];
  1448. r.obj:=self;
  1449. first_call_helper:=tprocedureofobject(r){$ifdef FPC}();{$endif FPC}
  1450. end;
  1451. function ttypeconvnode.pass_1 : tnode;
  1452. begin
  1453. result:=nil;
  1454. firstpass(left);
  1455. if codegenerror then
  1456. exit;
  1457. { load the value_str from the left part }
  1458. registers32:=left.registers32;
  1459. registersfpu:=left.registersfpu;
  1460. {$ifdef SUPPORT_MMX}
  1461. registersmmx:=left.registersmmx;
  1462. {$endif}
  1463. location.loc:=left.location.loc;
  1464. if nf_explizit in flags then
  1465. begin
  1466. { check if the result could be in a register }
  1467. if not(tstoreddef(resulttype.def).is_intregable) and
  1468. not(tstoreddef(resulttype.def).is_fpuregable) then
  1469. make_not_regable(left);
  1470. end;
  1471. result:=first_call_helper(convtype);
  1472. end;
  1473. function ttypeconvnode.docompare(p: tnode) : boolean;
  1474. begin
  1475. docompare :=
  1476. inherited docompare(p) and
  1477. (convtype = ttypeconvnode(p).convtype);
  1478. end;
  1479. {*****************************************************************************
  1480. TISNODE
  1481. *****************************************************************************}
  1482. constructor tisnode.create(l,r : tnode);
  1483. begin
  1484. inherited create(isn,l,r);
  1485. end;
  1486. function tisnode.det_resulttype:tnode;
  1487. var
  1488. paras: tcallparanode;
  1489. begin
  1490. result:=nil;
  1491. resulttypepass(left);
  1492. resulttypepass(right);
  1493. set_varstate(left,true);
  1494. set_varstate(right,true);
  1495. if codegenerror then
  1496. exit;
  1497. if (right.resulttype.def.deftype=classrefdef) then
  1498. begin
  1499. { left must be a class }
  1500. if is_class(left.resulttype.def) then
  1501. begin
  1502. { the operands must be related }
  1503. if (not(tobjectdef(left.resulttype.def).is_related(
  1504. tobjectdef(tclassrefdef(right.resulttype.def).pointertype.def)))) and
  1505. (not(tobjectdef(tclassrefdef(right.resulttype.def).pointertype.def).is_related(
  1506. tobjectdef(left.resulttype.def)))) then
  1507. CGMessage2(type_e_classes_not_related,left.resulttype.def.typename,
  1508. tclassrefdef(right.resulttype.def).pointertype.def.typename);
  1509. end
  1510. else
  1511. CGMessage1(type_e_class_type_expected,left.resulttype.def.typename);
  1512. { call fpc_do_is helper }
  1513. paras := ccallparanode.create(
  1514. left,
  1515. ccallparanode.create(
  1516. right,nil));
  1517. result := ccallnode.createintern('fpc_do_is',paras);
  1518. left := nil;
  1519. right := nil;
  1520. end
  1521. else if is_interface(right.resulttype.def) then
  1522. begin
  1523. { left is a class }
  1524. if is_class(left.resulttype.def) then
  1525. begin
  1526. { the operands must be related }
  1527. if not(assigned(tobjectdef(left.resulttype.def).implementedinterfaces) and
  1528. (tobjectdef(left.resulttype.def).implementedinterfaces.searchintf(right.resulttype.def)<>-1)) then
  1529. CGMessage2(type_e_classes_not_related,left.resulttype.def.typename,right.resulttype.def.typename);
  1530. end
  1531. { left is an interface }
  1532. else if is_interface(left.resulttype.def) then
  1533. begin
  1534. { the operands must be related }
  1535. if (not(tobjectdef(left.resulttype.def).is_related(tobjectdef(right.resulttype.def)))) and
  1536. (not(tobjectdef(right.resulttype.def).is_related(tobjectdef(left.resulttype.def)))) then
  1537. CGMessage(type_e_mismatch);
  1538. end
  1539. else
  1540. CGMessage1(type_e_class_type_expected,left.resulttype.def.typename);
  1541. { call fpc_do_is helper }
  1542. paras := ccallparanode.create(
  1543. left,
  1544. ccallparanode.create(
  1545. right,nil));
  1546. result := ccallnode.createintern('fpc_do_is',paras);
  1547. left := nil;
  1548. right := nil;
  1549. end
  1550. else
  1551. CGMessage1(type_e_class_or_interface_type_expected,right.resulttype.def.typename);
  1552. resulttype:=booltype;
  1553. end;
  1554. function tisnode.pass_1 : tnode;
  1555. begin
  1556. internalerror(200204254);
  1557. result:=nil;
  1558. end;
  1559. { dummy pass_2, it will never be called, but we need one since }
  1560. { you can't instantiate an abstract class }
  1561. procedure tisnode.pass_2;
  1562. begin
  1563. end;
  1564. {*****************************************************************************
  1565. TASNODE
  1566. *****************************************************************************}
  1567. constructor tasnode.create(l,r : tnode);
  1568. begin
  1569. inherited create(asn,l,r);
  1570. call := nil;
  1571. end;
  1572. destructor tasnode.destroy;
  1573. begin
  1574. call.free;
  1575. inherited destroy;
  1576. end;
  1577. function tasnode.det_resulttype:tnode;
  1578. var
  1579. hp : tnode;
  1580. b : boolean;
  1581. o : tobjectdef;
  1582. begin
  1583. result:=nil;
  1584. resulttypepass(right);
  1585. resulttypepass(left);
  1586. set_varstate(right,true);
  1587. set_varstate(left,true);
  1588. if codegenerror then
  1589. exit;
  1590. if (right.resulttype.def.deftype=classrefdef) then
  1591. begin
  1592. { left must be a class }
  1593. if is_class(left.resulttype.def) then
  1594. begin
  1595. { the operands must be related }
  1596. if (not(tobjectdef(left.resulttype.def).is_related(
  1597. tobjectdef(tclassrefdef(right.resulttype.def).pointertype.def)))) and
  1598. (not(tobjectdef(tclassrefdef(right.resulttype.def).pointertype.def).is_related(
  1599. tobjectdef(left.resulttype.def)))) then
  1600. CGMessage2(type_e_classes_not_related,left.resulttype.def.typename,
  1601. tclassrefdef(right.resulttype.def).pointertype.def.typename);
  1602. end
  1603. else
  1604. CGMessage1(type_e_class_type_expected,left.resulttype.def.typename);
  1605. resulttype:=tclassrefdef(right.resulttype.def).pointertype;
  1606. end
  1607. else if is_interface(right.resulttype.def) then
  1608. begin
  1609. { left is a class }
  1610. if is_class(left.resulttype.def) then
  1611. begin
  1612. { the operands must be related
  1613. no, because the class instance could be a child class of the current one which
  1614. implements additional interfaces (FK)
  1615. b:=false;
  1616. o:=tobjectdef(left.resulttype.def);
  1617. while assigned(o) do
  1618. begin
  1619. if assigned(o.implementedinterfaces) and
  1620. (o.implementedinterfaces.searchintf(right.resulttype.def)<>-1) then
  1621. begin
  1622. b:=true;
  1623. break;
  1624. end;
  1625. o:=o.childof;
  1626. end;
  1627. if not(b) then
  1628. CGMessage2(type_e_classes_not_related,left.resulttype.def.typename,right.resulttype.def.typename);
  1629. }
  1630. end
  1631. { left is an interface }
  1632. else if is_interface(left.resulttype.def) then
  1633. begin
  1634. { the operands must be related
  1635. we don't necessarily know how the both interfaces are implemented, so we can't do this check (FK)
  1636. if (not(tobjectdef(left.resulttype.def).is_related(tobjectdef(right.resulttype.def)))) and
  1637. (not(tobjectdef(right.resulttype.def).is_related(tobjectdef(left.resulttype.def)))) then
  1638. CGMessage2(type_e_classes_not_related,left.resulttype.def.typename,right.resulttype.def.typename);
  1639. }
  1640. end
  1641. else
  1642. CGMessage1(type_e_class_type_expected,left.resulttype.def.typename);
  1643. resulttype:=right.resulttype;
  1644. { load the GUID of the interface }
  1645. if (right.nodetype=typen) then
  1646. begin
  1647. if assigned(tobjectdef(right.resulttype.def).iidguid) then
  1648. begin
  1649. hp:=cguidconstnode.create(tobjectdef(right.resulttype.def).iidguid^);
  1650. right.free;
  1651. right:=hp;
  1652. end
  1653. else
  1654. internalerror(200206282);
  1655. resulttypepass(right);
  1656. end;
  1657. end
  1658. else
  1659. CGMessage1(type_e_class_or_interface_type_expected,right.resulttype.def.typename);
  1660. end;
  1661. function tasnode.getcopy: tnode;
  1662. begin
  1663. result := inherited getcopy;
  1664. if assigned(call) then
  1665. tasnode(result).call := call.getcopy
  1666. else
  1667. tasnode(result).call := nil;
  1668. end;
  1669. function tasnode.pass_1 : tnode;
  1670. var
  1671. procname: string;
  1672. begin
  1673. result:=nil;
  1674. if not assigned(call) then
  1675. begin
  1676. if is_class(left.resulttype.def) and
  1677. (right.resulttype.def.deftype=classrefdef) then
  1678. call := ccallnode.createinternres('fpc_do_as',
  1679. ccallparanode.create(left,ccallparanode.create(right,nil)),
  1680. resulttype)
  1681. else
  1682. begin
  1683. if is_class(left.resulttype.def) then
  1684. procname := 'fpc_class_as_intf'
  1685. else
  1686. procname := 'fpc_intf_as';
  1687. call := ccallnode.createinternres(procname,
  1688. ccallparanode.create(right,ccallparanode.create(left,nil)),
  1689. resulttype);
  1690. end;
  1691. left := nil;
  1692. right := nil;
  1693. firstpass(call);
  1694. if codegenerror then
  1695. exit;
  1696. location.loc:=call.location.loc;
  1697. registers32:=call.registers32;
  1698. registersfpu:=call.registersfpu;
  1699. {$ifdef SUPPORT_MMX}
  1700. registersmmx:=call.registersmmx;
  1701. {$endif SUPPORT_MMX}
  1702. end;
  1703. end;
  1704. begin
  1705. ctypeconvnode:=ttypeconvnode;
  1706. casnode:=tasnode;
  1707. cisnode:=tisnode;
  1708. end.
  1709. {
  1710. $Log$
  1711. Revision 1.90 2002-11-27 11:29:21 peter
  1712. * when converting from and to currency divide or multiple the
  1713. result by 10000
  1714. Revision 1.89 2002/11/25 17:43:18 peter
  1715. * splitted defbase in defutil,symutil,defcmp
  1716. * merged isconvertable and is_equal into compare_defs(_ext)
  1717. * made operator search faster by walking the list only once
  1718. Revision 1.88 2002/11/17 16:31:56 carl
  1719. * memory optimization (3-4%) : cleanup of tai fields,
  1720. cleanup of tdef and tsym fields.
  1721. * make it work for m68k
  1722. Revision 1.87 2002/10/10 16:07:57 florian
  1723. + several widestring/pwidechar related stuff added
  1724. Revision 1.86 2002/10/06 16:10:23 florian
  1725. * when compiling <interface> as <interface> we can't assume
  1726. anything about relation
  1727. Revision 1.85 2002/10/05 12:43:25 carl
  1728. * fixes for Delphi 6 compilation
  1729. (warning : Some features do not work under Delphi)
  1730. Revision 1.84 2002/10/02 20:23:50 florian
  1731. - removed the relation check for <class> as <interface> because we don't
  1732. know the runtime type of <class>! It could be a child class of the given type
  1733. which implements additional interfaces
  1734. Revision 1.83 2002/10/02 20:17:14 florian
  1735. + the as operator for <class> as <interface> has to check the parent classes as well
  1736. Revision 1.82 2002/09/30 07:00:47 florian
  1737. * fixes to common code to get the alpha compiler compiled applied
  1738. Revision 1.81 2002/09/16 14:11:13 peter
  1739. * add argument to equal_paras() to support default values or not
  1740. Revision 1.80 2002/09/07 20:40:23 carl
  1741. * cardinal -> longword
  1742. Revision 1.79 2002/09/07 15:25:03 peter
  1743. * old logs removed and tabs fixed
  1744. Revision 1.78 2002/09/07 12:16:04 carl
  1745. * second part bug report 1996 fix, testrange in cordconstnode
  1746. only called if option is set (also make parsing a tiny faster)
  1747. Revision 1.77 2002/09/05 05:56:07 jonas
  1748. - reverted my last commit, it was completely bogus :(
  1749. Revision 1.75 2002/09/02 19:24:42 peter
  1750. * array of char support for Str()
  1751. Revision 1.74 2002/09/01 08:01:16 daniel
  1752. * Removed sets from Tcallnode.det_resulttype
  1753. + Added read/write notifications of variables. These will be usefull
  1754. for providing information for several optimizations. For example
  1755. the value of the loop variable of a for loop does matter is the
  1756. variable is read after the for loop, but if it's no longer used
  1757. or written, it doesn't matter and this can be used to optimize
  1758. the loop code generation.
  1759. Revision 1.73 2002/08/23 16:14:49 peter
  1760. * tempgen cleanup
  1761. * tt_noreuse temp type added that will be used in genentrycode
  1762. Revision 1.72 2002/08/20 18:23:33 jonas
  1763. * the as node again uses a compilerproc
  1764. + (untested) support for interface "as" statements
  1765. Revision 1.71 2002/08/19 19:36:43 peter
  1766. * More fixes for cross unit inlining, all tnodes are now implemented
  1767. * Moved pocall_internconst to po_internconst because it is not a
  1768. calling type at all and it conflicted when inlining of these small
  1769. functions was requested
  1770. Revision 1.70 2002/08/17 09:23:36 florian
  1771. * first part of procinfo rewrite
  1772. Revision 1.69 2002/08/14 19:26:55 carl
  1773. + generic int_to_real type conversion
  1774. + generic unaryminus node
  1775. Revision 1.68 2002/08/11 16:08:55 florian
  1776. + support of explicit type case boolean->char
  1777. Revision 1.67 2002/08/11 15:28:00 florian
  1778. + support of explicit type case <any ordinal type>->pointer
  1779. (delphi mode only)
  1780. Revision 1.66 2002/08/09 07:33:01 florian
  1781. * a couple of interface related fixes
  1782. Revision 1.65 2002/07/29 21:23:42 florian
  1783. * more fixes for the ppc
  1784. + wrappers for the tcnvnode.first_* stuff introduced
  1785. Revision 1.64 2002/07/23 12:34:30 daniel
  1786. * Readded old set code. To use it define 'oldset'. Activated by default
  1787. for ppc.
  1788. Revision 1.63 2002/07/23 09:51:22 daniel
  1789. * Tried to make Tprocsym.defs protected. I didn't succeed but the cleanups
  1790. are worth comitting.
  1791. Revision 1.62 2002/07/22 11:48:04 daniel
  1792. * Sets are now internally sets.
  1793. Revision 1.61 2002/07/20 17:16:02 florian
  1794. + source code page support
  1795. Revision 1.60 2002/07/20 11:57:54 florian
  1796. * types.pas renamed to defbase.pas because D6 contains a types
  1797. unit so this would conflicts if D6 programms are compiled
  1798. + Willamette/SSE2 instructions to assembler added
  1799. Revision 1.59 2002/07/01 16:23:53 peter
  1800. * cg64 patch
  1801. * basics for currency
  1802. * asnode updates for class and interface (not finished)
  1803. Revision 1.58 2002/05/18 13:34:09 peter
  1804. * readded missing revisions
  1805. }