ncnv.pas 92 KB

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