ncnv.pas 93 KB

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