ncnv.pas 72 KB

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