ncnv.pas 94 KB

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